使用
sets
因此,这是有效测试交叉口的唯一方法。:
confirmed = [(60, 176), (60, 174), (63, 163), (61, 176)]
white = [(64, 178), (60, 174), (61, 176)]
要到达十字路口:
print(set(confirmed).intersection(white))
# {(60, 174), (61, 176)}
得到
True
或
False
,只需将结果集转换为
bool
:空集为False,非空集为True:
print(bool(set(confirmed).intersection(white)))
# True
另一个例子,有空交集:
confirmed = [(60, 176), (600, 174), (63, 163), (6100, 176)]
white = [(64, 178), (60, 174), (61, 176)]
print(set(confirmed).intersection(white))
# set()
print(bool(set(confirmed).intersection(white)))
# False