Try this,
(尝试这个,)
x in mylist
is better and more readable than x in mylist[:]
and your len(x)
should be equal to 3
.
(x in mylist
中的x in mylist[:]
比x in mylist[:]
更好,更易读x in mylist[:]
并且len(x)
应该等于3
。)
>>> mylist = [[1,2,3],[4,5,6,7],[8,9,10]]
>>> for x in mylist:
... if len(x)==3:
... print x
...
[1, 2, 3]
[8, 9, 10]
or if you need more pythonic use list-comprehensions
(或者如果您需要更多的pythonic使用list-comprehensions)
>>> [x for x in mylist if len(x)==3]
[[1, 2, 3], [8, 9, 10]]
>>>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…