【发布时间】:2020-09-19 11:02:17
【问题描述】:
boxes = [[0,0],[1,0],[2,0],[3,0],[4,0]]
x,y = 2,2
if (x,y) in boxes:
operation...
我不知道如何知道 x,y 是否在列表框中。
【问题讨论】:
boxes = [[0,0],[1,0],[2,0],[3,0],[4,0]]
x,y = 2,2
if (x,y) in boxes:
operation...
我不知道如何知道 x,y 是否在列表框中。
【问题讨论】:
怎么样:
if [x, y] in boxes:
operation...
这会将[x, y] 与框中的每个列表进行比较。但请注意,它不会检查[x, y] 的所有元素是否都存在于子列表中,因此子列表需要完全 等于[x, y] p>
所以 [1, 2] != [2, 1]
【讨论】:
试试这个。
boxes = [[0,0],[1,0],[2,0],[3,0],[4,0]]
expected = [2,2]
if expected in boxes:
print("Do your operation")
【讨论】: