0

If I have an (x,y) coordinate e.g. (1,4) how can I check if it matches a coordinate in another set of randomly generated coordinates e.g. [(3,5),(7,3),(6,9),(1,4)]?

I have tried lots of different ways and keep getting error messages. TIA for any advice.

SiHa
  • 7,830
  • 13
  • 34
  • 43
ATN
  • 9
  • 1
  • What about using the `in` operator? `coordinate in list`... – Willem Van Onsem Jan 30 '17 at 16:05
  • Possible duplicate of [Fastest way to check if a value exist in a list](http://stackoverflow.com/questions/7571635/fastest-way-to-check-if-a-value-exist-in-a-list) – SiHa Jan 30 '17 at 21:56

1 Answers1

0

Use the in operator for that

a = (1,4)
b = [(3,5),(7,3),(6,9),(1,4)] 
print (a in b)
>>> 'True'
SiHa
  • 7,830
  • 13
  • 34
  • 43
omri_saadon
  • 10,193
  • 7
  • 33
  • 58
  • Thanks for you;re super quick answer :) I have tried this but it gives error that function is not iterable. As I want to say if a in b ==True: then for it to do an action?? – ATN Jan 30 '17 at 16:16
  • @ATN you should do it like this: `print ((a in b) == True)`, Although it's not the right coding style, the answer i wrote is the appropriate way. (a in b) equals to ((a in b) == True), but the code is more elegant the first way. – omri_saadon Jan 30 '17 at 16:19