I would like to know what\'s the general behaviour of an iterator if the underlaying object changes during the iteration.
Using a simple mutable list, it seems obvi
There are three typical behaviours of changing an object while iterating over it:
In other words: the actual behaviour is undefined.
Changing objects while iterating over them was such a common problem that in Python 3 the types set
and dict
(and possibly others) were changed to immediately raise an error if additions or removals were detected during iteration.