Charan Singh Charan Singh - 2 months ago 10
Python Question

Searching two of the three characters in python

info=('x','y','z')
info2=('x','Bob','y')
match=False
if any(all x in info for x in info2):
match=True
print("True")
else:
print("False")


Is that is there a way I can make it work so that it only prints
True
when
x
and either
y
or
z
are in
info2
?

Answer

The way I read this you want the first element in info (info[0]), and at least one other element in info to be in info2

 if info[0] in info2 and any(i in info2 for i in info[1:]):
     # do stuff