如何识别多个坐标数组中是否存在一对坐标(x1,y1)?例如,在某种代码中:
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
我一直在试验任何(),但不能正确使用语法,或者它不是正确的方法。 感谢
答案 0 :(得分:2)
使用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
或将any
与generator expression一起使用:
>>> any(myCoord in x for x in (someCoords1, someCoords2))
True