2015-01-10 220 views
0

如何識別多個座標數組中是否存在一對座標(x1,y1)?例如在一種代碼:標識python x,y數組中的x,y座標對

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 

我一直在試驗任何(),但不能得到正確的語法或它不是正確的方法。 感謝

回答

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 

或使用anygenerator expression

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