mark
mark

Reputation: 557

identify x,y coordinate pair in a python x,y array

how can i identify the presence or absence of a pair of coordinates (x1,y1) in an array of many coordinates? eg in a sort of code:

myCoord = [1,2]

someCoords1 = [[2,3][4,5][1,2][6,7]]
someCoords2 = [[2,3][4,5][8,9][6,7]]

myCoord in someCoords1
True

myCoord in someCoords2
False

I have been experimenting with any() but can't get the syntax right or it's not the correct method. thanks

Upvotes: 0

Views: 1157

Answers (1)

falsetru
falsetru

Reputation: 369074

Using or operator:

>>> myCoord = [1,2]
>>> someCoords1 = [[2,3], [4,5], [1,2], [6,7]]
>>> someCoords2 = [[2,3], [4,5], [8,9], [6,7]]
>>> myCoord in someCoords1 or myCoord in someCoords2
True

or using any with generator expression:

>>> any(myCoord in x for x in (someCoords1, someCoords2))
True

Upvotes: 2

Related Questions