The task is to remove all the zeros from a list, so I wrote the following code:
a = [9, 0, 0, 9, 1, 2, 0, 1, 0, 1, 0, 3, 0, 1, 9, 0, 0, 0, 0, 9]
for i in a:
if i == 0:
a.remove(i)
print(a)
the output is:
[9, 9, 1, 2, 1, 1, 3, 1, 9, 0, 0, 0, 9]
for some reason it removes only one zero after the penultimate 9 and then stops. Could anyone explain why didn't it remove every single one?