I understand that modifying a list while iterating over it can spell disaster. I was curious so I tried it anyway. In the first few examples below, things go as expected; but then something unusual happens in the second to last example.
>>> A = [0, 0, 0, 0]
>>> for k in A:
if k == 0:
A.remove(k)
>>> A
[0, 0]
>>> A = [0, 0, 0, 0, 1]
>>> for k in A:
if k == 0:
A.remove(k)
>>> A
[0, 0, 1]
>>> A = [0, 0, 0, 0, 1, 1]
>>> for k in A:
if k == 0:
A.remove(k)
>>> A
[0, 0, 1, 1]
>>> A = [0, 0, 0, 0, 1, 1, 0] # Why does the presence of a fifth zero (the one at the end), cause an earlier zero to be removed?
>>> for k in A:
if k == 0:
A.remove(k)
>>> A
[0, 1, 1, 0]
>>> A = [0, 0, 0, 0, 1, 1, 2]
>>> for k in A:
if k == 0:
A.remove(k)
>>> A
[0, 0, 1, 1, 2]