3 ms·
It seems people dont realize that you can have your cake and eat it too. You can have both orderered and unordered maps in the same language: https://yaml.org/
by svnpenn 7y ago
It seems people dont realize that you can have your cake and eat it too. You can have both orderered and unordered maps in the same language:
https://yaml.org/type/map https://yaml.org/type/map
https://yaml.org/type/omap https://yaml.org/type/omap
No reason to argue about which one to make "dict". In fact it would be better to have both because youre taking a performance hit (a significant one) by ordering the entries.
- lvh 7y agoThe new dict does not come with a performance hit, let alone a significant one. It’s much more memory efficient and generally slightly faster.
- svnpenn 7y agopretty strong evidence to the contrary https://apps.dtic.mil/dtic/tr/fulltext/u2/a627127.pdf https://apps.dtic.mil/dtic/tr/fulltext/u2/a627127.pdf do you have any references to back your claim that its actually faster?
- joshuamorton 7y agohttps://morepypy.blogspot.com/2015/01/faster-more-memory-efficient-and-more.html https://morepypy.blogspot.com/2015/01/faster-more-memory-eff... The new python dict implementation is benchmarked as faster in both microbenchmarks and in practice for almost all real-world workloads. Note that this isn't a sorted map, like C++'s "Ordered Map", but an Ordered map. C++ get's the name wrong. Items aren't ordered by key comparison, but ordered by insertion time.
- svnpenn 7y agoGood link, thanks
- masklinn 7y agoPython has had both ordered and unordered maps in the same languages for 10 years or so (OrderedDict was added to the stdlib in 2009). In 2016, the standard dict was moved to a new and more efficient implementation (more compact & faster to iterate). It was naturally ordered, and so as a side-effect of this change and since the CPython devs did not explicitly scramble it, iteration on dicts became both deterministic and specific (it would always follow insertion order). This was considered both a boon because conserving iteration order is strictly more useful than not doing it and a woe because it would cause compatibility issues with third-party implementations or further changes down the line as users would absolutely start relying on the iteration order even if it was still considered unspecified. So in the next major release they decided to resolve the issue by making this behaviour part of the language. It restricts future design space, but they can always add an unordered dict as part of the stdlib if that ever truly becomes useful so meh.