If somebody tries:
my_dict = {1: 1}
for key in my_dict:
my_dict.pop(key)
one will get:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
RuntimeError: dictionary changed size during iteration
Python will throw an error, since you changed the size of the dict while looping over it.
How does Python know that this has happened, and can this feature be overrided programmatically so that the code runs?
And before somebody asks the inevitable question of "why I would want to do this": I don't. I'm asking a question. It's called curiosity.
FOR EXAMPLE:
Say I have a dict with 5 items. The above code should simply delete all items in the dict!