[英]python how to check if a nested list contain all None values
我有一個看起來像這樣的列表
[[None, None, None], [None, None, None]]
如何有效地檢查所有元素都沒有?
我知道如何做到這一點
lst = [None, None, None]
all(item is None for item in lst )
您可以這樣做,一旦遇到與None
不同的值, all
將返回False
:
lst = [[None, None, None], [None, None, None]]
all(item is None for sublist in lst for item in sublist)
# True
嘗試這個:
def checkList(lstInput):
for i in lst:
for j in i:
if j!=None:
return False
return True
lst=[[None,None,None],[None,None,None]]
print(checkList(lst))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.