I have a list that contains more lists and zeros.
checks =[[1], [2, 6, 10, 9], [3, 7, 8], [4], [5], 0, 0, 0, 0, 0, [11]]
I intend to remove all the zeros and the lists having length one. I wrote the following code and expected the output to be:
checks = [[2,6,10,9], [3,7,8]]
instead, the output came out to be:
checks = [[2,6,10,9], [3,7,8], [5]]
code:
while 0 in checks:
checks.remove(0)
for x in checks:
if len(x) < 2:
checks.remove(x)
print(checks)
Why is my code not removing the single element list [5] from the given list? I ran this piece of code on many IDEs, but the result was the same. Is it some flaw of Python or am I missing some key concept? It would be really helpful if someone can explain this behavior of Python and give a fix for the same.