On 16Dec2019 0417, Petr Viktorin wrote:
Originally, making dicts ordered was all about performance (or rather memory efficiency, which falls in the same bucket.) It wasn't added because it's better semantics-wise.
Here's one (very simplified and maybe biased) view of the history of dicts:

* 2.x: Dicts are unordered, please don't rely on the order.
* 3.3: Dict iteration order is now randomized. We told you not to rely on it! * 3.6: We now use an optimized implementation of dict that saves memory! As a side effect it makes dicts ordered, but that's an implementation detail, please don't rely on it. * 3.7: Oops, people are now relying on dicts being ordered. Insisting on people not relying on it is battling windmills. Also, it's actually useful sometimes, and alternate implementations can support it pretty easily. Let's make it a language feature! (Later it turns out MicroPython can't support it easily. Tough luck.)

For the record, we missed out on a very memory efficient "frozendict" implementation because it can't maintain insertion order - Yury is currently proposing it as FrozenMap in PEP 603. https://discuss.python.org/t/pep-603-adding-a-frozenmap-type-to-collections/2318

Codifying semantics isn't always the kind of future-proof we necessarily want to have :)

Cheers,
Steve
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/Y7YP7SKSQOGOCXNXV27ZGSQDUVZRPSPH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to