I have two lists where I want to check if elements from a exists in b
a=[1,2,3,4]
b=[4,5,6,7,8,1]
This is what I tried ( didn't work though!)
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)
I want to check if elements from a exists in b and should set a flag accordingly. Any thoughts?
return Trueas soon as you find the first element that is in bothaandb