I had someone recently ask me recently about the faux pas of changing a list while iterating over it. They presented the following scenario (which I have now updated with a better example) as a possible use case when the behavior might be desirable:
>>> jersey_numbers = [4, 2, 3, 5, 1] # list of places in a race
>>> for jersey_number in jersey_numbers:
if jersey_number == 2: # disqualify jersey number 2 for a false start
t.remove(jersey_number)
>>> t
[4, 3, 5, 1] # jersey number 3 is now in second place
Is this behavior regular enough to use in a use case such as this one?