Python:一种通过类似于';在';操作人员

Python:一种通过类似于';在';操作人员,python,Python,我在互联网上徘徊了一段时间,找不到一个方法来做到这一点。“in”运算符仅适用于列表的表面级别,但它是一种检查所有子列表中某个值的方法,而不使用for?见示例: >>> a = [1,2,3] >>> 1 in a True #this is good >>> a = [[1,2],[3,4]] >>> 1 in a False #I would want this to be true, as there is a 1 in

我在互联网上徘徊了一段时间,找不到一个方法来做到这一点。“in”运算符仅适用于列表的表面级别,但它是一种检查所有子列表中某个值的方法,而不使用for?见示例:

>>> a = [1,2,3]
>>> 1 in a
True #this is good
>>> a = [[1,2],[3,4]]
>>> 1 in a
False #I would want this to be true, as there is a 1 in a[0]
如果有人能告诉我一种手动保存迭代的方法,那就太好了。:)

您可以使用运算符:

>>> a = [[1, 2], [3, 4]]
>>> any(1 in lst for lst in a)
True

但是对于大于两个嵌套的任何东西,我会说使用一个循环,否则代码会变得非常混乱

a在它里面有一个列表,在那些列表中有1个