[List 1]
a
b
c
d
e
[List 2]
e
f
g
a
b
If there are two lists, compare List 1 with List 2 in total Return 1 because element a is in list 2, and return 1 because element b is in list 2, Since c, d, and e are not in list 2, return each to 0, 0, 0, 1, 1, and so on I want to make it come out, but what should I do??
The question is too long and the words seem strange, but please help me...
python list
In [1]: list1 = ['a', 'b', 'c', 'd' ,'e']
In [2]: list2 = ['e', 'f', 'g', 'a', 'b']
In [3]: list(map(lambda i: 1 if i in list1 else 0, list2))
Out[3]: [1, 0, 0, 1, 1]
In [4]: [1 if i in list1 else 0 for i in list2]
Out[4]: [1, 0, 0, 1, 1]
© 2024 OneMinuteCode. All rights reserved.