How to have Boolean results from the interaction of two lists?
That is:
a = [1,2,3,4,5]
b = [2,4]
for each item in a
that belongs to b
return true
How to have Boolean results from the interaction of two lists?
That is:
a = [1,2,3,4,5]
b = [2,4]
for each item in a
that belongs to b
return true
You can iterate this way:
for x in a:
print(x in b)
Or so:
for x in a:
if x in b:
print(x) # ou print(x in b)
If you want to save the items that are common among the lists, in a new list do so:
c = set(a).intersection(set(b))
c = list(c)