如果x在多个列表中的任何一个列表中,我该如何返回True?

Pea*_*ser 3 python return list

>>> list1 = ['yes', 'yeah']
>>> list2 = ['no', 'nope']
>>> 'no' in list2
True
>>> 'no' in list1
False
>>> 'no' in (list1, list2)
False
>>> 'no' in (list1 and list2)
True
>>> 'yes' in (list1 and list2)
False #want this to be true
>>> 'yes' in (list1 or list2)
True
>>> 'no' in (list1 or list2)
False #want this to be true
>>>
Run Code Online (Sandbox Code Playgroud)

如你所见,我无处可去.

如果x或y在任一列表中,我怎样才能使它返回true?

ssh*_*124 10

你可以这样做any:

>>> any('yes' in i for i in (list1, list2))
True
Run Code Online (Sandbox Code Playgroud)

或者,只是连接列表:

>>> 'yes' in list1+list2
True
Run Code Online (Sandbox Code Playgroud)