Skip to content
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

Dict is now ordered. Maybe the book should be updated? #95

Open
gbnewb opened this issue Jun 1, 2022 · 4 comments
Open

Dict is now ordered. Maybe the book should be updated? #95

gbnewb opened this issue Jun 1, 2022 · 4 comments

Comments

@gbnewb
Copy link

gbnewb commented Jun 1, 2022

As of Python 3.6, for the CPython implementation of Python, dictionaries remember the order of items inserted. This is considered an implementation detail in Python 3.6; you need to use OrderedDict if you want insertion ordering that's guaranteed across other implementations of Python.

As of Python 3.7, this is a guaranteed language feature, not merely an implementation detail.

@mcmwebsol
Copy link

I think Section 11.1 should be updated regarding this.

@AllenDowney
Copy link
Owner

AllenDowney commented Feb 22, 2024 via email

@mcmwebsol
Copy link

As of Python 3.7 it's part of the Python language specification. https://docs.python.org/3/whatsnew/3.7.html -
"the insertion-order preservation nature of dict objects has been declared to be an official part of the Python language spec."

Also from https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects -
"Dictionaries preserve insertion order. Note that updating a key does not affect the order. Keys added after deletion are inserted at the end."

@AllenDowney
Copy link
Owner

AllenDowney commented Feb 22, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants