-
Notifications
You must be signed in to change notification settings - Fork 1.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
Dict is now ordered. Maybe the book should be updated? #95
Comments
I think Section 11.1 should be updated regarding this. |
As I understand it, ordered dictionaries are not part of the Python language specification, they are an implementation detail of some versions of CPython.
The book specifies Python 3 but not which implementation or version. So I don't think I can generally say that dictionaries are ordered.
On Thu, Feb 22, 2024, at 11:26 AM, Joseph McMurry wrote:
I think Section 11.1 should be updated regarding this.
—
Reply to this email directly, view it on GitHub <#95 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAOLP3KWPVYB4JIFS22IMCLYU5WTDAVCNFSM5XRWLHZKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJVHE4DAOBXG4ZQ>.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
—
Allen Downey
*Probably Overthinking It*: probablyoverthinking.it
|
As of Python 3.7 it's part of the Python language specification. https://docs.python.org/3/whatsnew/3.7.html - Also from https://docs.python.org/3/library/stdtypes.html#dictionary-view-objects - |
Fair enough -- but still, the book doesn't specify a version, and for the target audience of Think Python, it's a detail we don't need at this point.
On Thu, Feb 22, 2024, at 11:40 AM, Joseph McMurry wrote:
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 <https://docs.python.org/3/library/stdtypes.html#typesmapping> objects has been declared <https://mail.python.org/pipermail/python-dev/2017-December/151283.html> 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."
—
Reply to this email directly, view it on GitHub <#95 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAOLP3KPPT23EPWXQ747KHTYU5YIVAVCNFSM5XRWLHZKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJVHE4DGNZRGM2Q>.
You are receiving this because you commented.Message ID: ***@***.***>
—
Allen Downey
*Probably Overthinking It*: probablyoverthinking.it
|
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.
The text was updated successfully, but these errors were encountered: