cegthgtlhj
cegthgtlhj

Reputation: 311

Python 3. How to find any member of one list in another list?

I have first list: x = ["abc", "cde", .... "sadlfj"] and the second list. y = ["ABC", "DRF", .... "CXV"] I need to check the following condition: if any member of list "x" is in the list "y", then TRUE. How to write this condition check without iteration? Thank you

Upvotes: 0

Views: 40

Answers (1)

user3456014
user3456014

Reputation:

Try sets, since you ask for the condition, not the actual elements in common:

x = [...]
y = [...]

if not set(x).isdisjoint(set(y)):
     # they have something in common

Upvotes: 3

Related Questions