I made this function which removes all the odd numbers from a list. (I can't modify the original list)
Code:-
def purify(sequence):
purified = sequence
for i in purified:
if i % 2 != 0:
purified.remove(i)
return purified
The function works on most of the list but if a list have same values like [4, 5, 5, 4]
it returns [4, 5, 4]
.
I have changed the code to achieve what I required but I am just curious why this happens?