4 ms·
Just to clarify. This behavior is expected since 3.6: As of Python 3.6, for the CPython implementation of Python, dictionaries remember the order of items inse
by bratao 8y ago
Just to clarify. This behavior is expected since 3.6:
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 no longer an implementation detail and instead becomes a language feature.
[1] https://stackoverflow.com/questions/39980323/are-dictionaries-ordered-in-python-3-6 https://stackoverflow.com/questions/39980323/are-dictionarie...
- blattimwind 8y agoCPython implementation detail vs. Python language feature remains a relatively meaningless distinction.
- anticensor 8y agoCPython is not the only Python interpreter out there.
- JeremyBanks 8y agoThe documentation sometimes suggests otherwise, but since there is no Python language specification, declaring something "part of the language" seems to have no meaning if it's not "implemented in CPython". PyPy has had ordered dicts for longer than CPython, and Jython and IronPython don't look like they're ever going to support Python 3, so I'm not sure who this declaration is even even hypothetically relevant to.
- richardwhiuk 8y agoIt's relevant in the fact that you shouldn't rely on it as a programmer prior to this release. Changing it would have been considered a none breaking change.
- JeremyBanks 8y agoGood point.
- earenndil 8y agoThe other major python implementation, pypy, effectively implements CPython. (And insofar as it doens't, it's heading that way.)
- setr 8y agoEven if you stick purely to CPython, it still matters in that there's no guarantee that it'll still be ordered when you update (if you were reading 3.6 dicts). It's not just an implementation detail for CPython, but an implementation detail for specifically CPython 3.6 (and any other version maintaining that status). So now that its upgraded to language feature, you can actually expect backwards compatibility in future updates.