我有两个列表,想要检查a中的元素是否存在于b中
a=[1,2,3,4]
b=[4,5,6,7,8,1]
这是我尝试过的(但没有成功!)
a=[1,2,3,4]
b=[4,5,6,7,3,1]
def detect(list_a, list_b):
for item in list_a:
if item in list_b:
return True
return False # not found
detect(a,b)
我想检查a中的元素是否存在于b中,并相应地设置一个标志。有什么想法吗?
a
和b
中第一个相同的元素,您就会立即返回True
。 - tobias_k