This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tim.peters
Recipients Saps, ammar2, tim.peters
Date 2018-10-19.03:36:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1539920209.57.0.788709270274.issue35023@psf.upfronthosting.co.za>
In-reply-to
Content
Questions about Python should be asked, e.g., on the Python mailing list.

The short course is that it's desired that iterating over dicts be as fast as possible, and nobody knows a way to make iteration robust in the face of mutations that wouldn't be significantly slower.  The dict implementation is quite involved, and a single mutation _can_ cause major restructuring of the internal layout.

As is, the dict implementation checks to see whether the dict _size_ has changed across iterations, and raises a RuntimeError if it has.  That's cheap.  When you both delete and add a key between iterations, the dict size doesn't change overall, so that runtime check doesn't trigger.
History
Date User Action Args
2018-10-19 03:36:49tim.peterssetrecipients: + tim.peters, ammar2, Saps
2018-10-19 03:36:49tim.peterssetmessageid: <1539920209.57.0.788709270274.issue35023@psf.upfronthosting.co.za>
2018-10-19 03:36:49tim.peterslinkissue35023 messages
2018-10-19 03:36:49tim.peterscreate