I want to check several Python list in operators.

Asked 6 days ago, Updated 6 days ago, 2 views

a = ['name','phone','email','birth'] ,
b = ['name','phone','birth']  

I want to get it returned as True/False if a value is included in b as in operator.

list(map(lambdax,y:x in y,a,b) I tried to see one by one, but only three b were shown.

Is there only a way to check a one by one using for statement?

python3 python

2022-09-20 14:58

2 Answers

Please keep that in mind.

a = ['name','phone','email','birth']
b = ['name','phone','birth']

[i in b for i in a]
[True, True, False, True]


2022-09-20 14:58

Please keep that in mind

a = ['name','phone','email','birth']
b = ['name','phone','birth']
c = ['aaaa','phone','birth', 'email']

import itertools as it

list(map(lambda t:len(set(t)) == 1, it.zip_longest(a, b, c)))
[False, True, False, False]


2022-09-20 14:58

If you have any answers or tips


© 2022 pinfo. All rights reserved.