【发布时间】:2019-08-10 08:17:39
【问题描述】:
我有 2 个像素坐标列表
(confirmed pixel[(60, 176), (60, 174), (63, 163), (61, 176)] &
white_pixel [(64, 178), (60, 174), (61, 176)])
我想比较它们,如果发现任何相同的值,例如 (61, 176) 和 (60, 174),它将返回True,表示至少需要匹配一个值。
我怎样才能在这个 if 语句中做到这一点?
confirmed_pixel == white_pixel 不能作为 all 两个列表中的值必须相同才能返回 true
if confirmed_pixel == white_pixel and len(confirmed_pixel) != 0 and len(white_pixel) != 0:
print("True")
continue
【问题讨论】:
-
你可以用循环来做到这一点。
-
您有两个
list和tuples。使用loop将第一个list中的每个tuple与第二个list中的所有其他tuples进行比较。在相等的情况下可以printTrue。 -
您好 Cytex,欢迎来到 SO。使用谷歌搜索很容易在 SO 上找到您的问题的重复项 - 我使用了这个:
python check if two lists share elements作为谷歌查询...
标签: python python-3.x list