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

Asked

Viewed 69 times

0

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

That is to say:

a = [1,2,3,4,5] 
b = [2,4] 

for each item in a belonging to b return true

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 store items that are common among lists, in a new list do so:

   c = set(a).intersection(set(b))
   c = list(c)
  • Hello Iron Man. Thank you very much for the suggestion, which is what I will apparently have to use. I thought there would be a library or that pandas would have an easier way of doing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.