[英]Check if a list contains any list
I want to check whether or not a list contains another list inside it.我想检查一个列表中是否包含另一个列表。 I don't care about the elements, I just want to check the existence of a nested list.
我不关心元素,我只想检查嵌套列表的存在。
I have done this:我已经这样做了:
nested_list = False
for element_of_list in b:
if isinstance(element_of_list, list):
nested_list = True
But I was wondering if there is a more Pythonic way to do this.但我想知道是否有更 Pythonic 的方法来做到这一点。
尝试使用any
:
print(any(isinstance(i, list) for i in b))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.