3 ms·
OrderedDicts have some convenience methods and features that ordinary dicts don't have.
by heavyset_go 2y ago
OrderedDicts have some convenience methods and features that ordinary dicts don't have.
- rbanffy 2y agoAlso, dicts can become unordered at any time in the future. Right now the OrderedDict implementation is a thin layer over dict, but there are no guarantees it’ll always be that.
- wodenokoto 2y agoThey can, but ordered dict can also become unordered in the future, should the steering committee decide. But seriously: It’s no longer an implementation detail that dictionaries are ordered in Python. It’s a specification of how Python works.
- rbanffy 2y agoI missed that in the 3.7 release notes.
- judicious 2y agoThere in lies another reason why OrderedDicts are still useful even in 3.12
- rbanffy 2y agoNot really. It was pointed out that since 3.7 the order preserving behaviour is part of the spec for dicts.
- judicious 2y agoI guess for most purposes, OrderedDicts are then obsolete, but I believe there are some extra convenience methods that they have, but I've only really needed to preserve order. Makes you think what other parts of Python have become obsolete.
- 3eb7988a1663 2y agoNot true as of 3.7[0] the insertion-order preservation nature of dict objects has been declared to be an official part of the Python language spec. [0] https://docs.python.org/3.7/whatsnew/3.7.html https://docs.python.org/3.7/whatsnew/3.7.html
- rbanffy 2y agoOh well... This is what I get to not look at release notes with lawyer eyes. Thanks for the correction.
- SuchAnonMuchWow 2y agodict are ordered to keep argument order when using named arguments in function calling. So it would be a non-trivial breaking change to revert this now. I would argue that OrderedDict have more chances to be depreciated than dict becoming unordered again, since there is now little value to keep OrderedDict around now (and the methods currently specific to UnorderedDict could be added to dict).
- wodenokoto 2y agoDo you have any examples?
- heavyset_go 2y agoCheck out the docs: https://docs.python.org/3/library/collections.html#collections.OrderedDict https://docs.python.org/3/library/collections.html#collectio...