How to have Boolean results from the interaction of two lists?

0

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

    
asked by anonymous 13.06.2016 / 16:29

1 answer

0

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)
    
14.06.2016 / 00:20