Tim Peters <t...@python.org> added the comment:
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. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue35023> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com