-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Output of "Modifying a dictionary while iterating over it" is not correct for all Python versions #53
Comments
For Python 3.6.4 on macOS 10.12:
|
Hey @icemac, thanks for reporting this. I'll investigate the reason for different behavior in the latest versions of Python. |
Okay, I dug up a little and found these differences in the implementation between Python In both the CPython versions, the hash table for dictionary starts with a size of 8 (Python 3.6.1 and Python 3.5.1). The resize occurs when the table size exceeds the Moreover, the way deleted keys are handled are probably different in both the Python version (I'm still trying to understand how they work), which leads to all the difference. I think this is highly implementation specific, so I've added a note in the example regarding the Python versions for now, and I'll link this issue in the example description (for further reading of interested readers) once we figure out how deletions are handled in both the versions of python. |
The result shown in Modifying a dictionary while iterating over it is correct for CPython 2.4 up to 3.5.
On Python 3.6 it prints
On PyPy 2.7 and PyPy 3 it prints
The text was updated successfully, but these errors were encountered: