Skip to main content
  1. About
  2. For Teams
Asked
Viewed 1k times
0

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

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.