要做到这一点,您有各种各样的蟒蛇解决方案:
方法1 :
bool(set(a) & set(b))
a = ['abc','bca','av'] b = ['ab','bc'] print(bool(set(a) & set(b))) # this would return true in this case
另一种方法
a = set(a); any(i in a for i in b)
以及 最后 可以使用冻结集的不相交方法:
not set(a).isdisjoint(b)