I want to check several Python list in operators.

Asked 2 years ago, Updated 2 years ago, 55 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


© 2024 OneMinuteCode. All rights reserved.