I have a list in python and every time an element satisfies a certain condition I remove the element. The problem is that the for cycle seems to be skipping some elements. I think it's because the list is moved to the left after a delete. So how to properly remove items in a list? This is my code
list = [0, 0, 0, 1, 1, 0 ,0, 1, 0]
for elem in list:
if elem == 0:
list.remove(elem)
print(list)
and this is the result [1, 1, 0, 1, 0]