That’s relatively new (introduced in Python 3.6). You wouldn’t believe how many production code bases are still in 3.5 or lower.
The change log for 3.6 states:
The order-preserving aspect of this new implementation is considered an implementation detail and should not be relied upon (this may change in the future, but it is desired to have this new dict implementation in the language for a few releases before changing the language spec to mandate order-preserving semantics for all current and future Python implementations; this also helps preserve backwards-compatibility with older versions of the language where random iteration order is still in effect, e.g. Python 3.5
Therefore it’s advisable to use OrderedDict if there’s even a chance this code might be used with older versions.
Yeah I recently learned about this after giving another engineer PR feedback that dicts are not ordered and we cannot expect the intended behavior. Jokes on me. Old habits die hard
loloquwowndueo|1 year ago
The change log for 3.6 states:
The order-preserving aspect of this new implementation is considered an implementation detail and should not be relied upon (this may change in the future, but it is desired to have this new dict implementation in the language for a few releases before changing the language spec to mandate order-preserving semantics for all current and future Python implementations; this also helps preserve backwards-compatibility with older versions of the language where random iteration order is still in effect, e.g. Python 3.5
Therefore it’s advisable to use OrderedDict if there’s even a chance this code might be used with older versions.
whalesalad|1 year ago
porridgeraisin|1 year ago
Normal dict = insertion order only (since some python version)
Haven't looked into why they need key ordering here though.
tempay|1 year ago