Open
Description
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.
Activity
mcmwebsol commentedon Feb 22, 2024
I think Section 11.1 should be updated regarding this.
AllenDowney commentedon Feb 22, 2024
mcmwebsol commentedon Feb 22, 2024
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 commentedon Feb 22, 2024