我有这样一个东西:
myList = [[1, None, None, None, None],[2, None, None, None, None],[3, 4, None, None, None]]
如果列表中的任何一个列表有4个Nones,我希望将它们删除,以便输出为:
myList = [[3, 4, None, None, None]]
我尝试使用以下方式:
for l in myList:
if(l.count(None) == 4):
myList.remove(l)
但是它只能一直删除其中的一半,尽管我知道if语句执行正确,会导致如下结果:
[[2, None, None, None, None], [3, 4, None, None, None]]
我用这种方法设法让它工作了,但似乎不太对:
for l in myList:
if(l.count(None) == 4):
del l[0]
del l[0]
del l[0]
del l[0]
del l[0]
myList = list(filter(None, myList))
有更好的方法吗?提前感谢。我正在使用Python 3.3。