-2

In Python, I have two lists of coordinates like [(2,4),(4,5)]. One is filled with 10 coordinates and the other is empty. I have the code set out so if the coordinate the player inputs is the array. It will append the coordinate to the empty array which will represent the 'visited' coordinates. I want an if statement that will check if the element of 'coordinate' appears in the 'visits' list twice.

def corcheck(coordinate,+10locations,+10visits,losecoinslocations,coins):
    if coordinate in +10locations:
        coins=coins+10
        coordinate.append(+10visits)
        print("+10")
#        if coordinate in
    elif coordinate in losecoinslocations:
        coins=0
        print("You lose all your coins. -",coins)
    else:
        print("This square was empty. Please make your next move.")
    return +10visits,+10num,losecoinsnum,coins

The line which is editied with #is where the check will be placed for if the coordinate element appears in +10 visits twice, from there it will be appended to losecoinslocations.

1 Answers1

1
if len(coordinate ) != len(set(coordinate )):

set removes duplicates , and check the lenth against original list

Shijo
  • 9,313
  • 3
  • 19
  • 31