RuntimeError: dictionary changed size during iteration

Terry Reedy tjreedy at
Tue Dec 9 19:25:10 CET 2008

Robert Dailey wrote:

> When I do:
> for key in stuff.keys():
> It works! I wonder why .keys() makes a difference. It is using a
> 'view', which is a new concept in Python 3.0 that I'm not totally
> familiar with yet.

Because stuff.keys() is evaluated *once* and the result is a separate 
object from stuff == globals(), so creating the new entry 'key' in 
globals == stuff does not change that new object.

More information about the Python-list mailing list