3 ms·
Dictionaries should not be assumed to keep their orderings anyway. That's why there's OrderredDict. Unless the language explicitly says that dicts hold their
by coldtea 8y ago
Dictionaries should not be assumed to keep their orderings anyway.
That's why there's OrderredDict.
Unless the language explicitly says that dicts hold their order, even if they do, it's an implementation detail, and it should not be relied upon.
- snicker7 8y agoAs of 3.7 (3.6 for cpython), dictionaries have a deterministic order.
- thro_away_n 8y agoWhat's the best way to write code that relies on this deterministic order and prevent it from running incorrectly with older python versions?
- b_tterc_p 8y agoImport collections.OrderedDict as you would have done beforehand. There are still some differences between them. (Dicts in 3.7 and ordered dicts) https://stackoverflow.com/questions/50872498/will-ordereddict-become-redundant-in-python-3-7 https://stackoverflow.com/questions/50872498/will-ordereddic...
- BerislavLopac 8y agoIf "the language explicitly says" something, then it's part of the specification and not an implementation detail.
- coldtea 8y agoSure, hence the "unless" I've used.