Earlier quoted context omitted.
As far as I know, it was implemented by Raymond Hettinger. This is a very interesting talk about the new tech: https://www.youtube.com/watch?v=p33CVV29OG8&t=1202s
Raymond came up with the idea, PyPy implemented it, and then INADA Naoki implemented it for CPython.
Python dicts are now ordered
231–240 of 457 posts
Re: Python dicts are now ordered
#232Earlier quoted context omitted.
The new dict does not come with a performance hit, let alone a significant one. It’s much more memory efficient and generally slightly faster.
pretty strong evidence to the contrary https://apps.dtic.mil/dtic/tr/fulltext/u2/a627127.pdf do you have any references to back your claim that its actually faster?
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.
Re: Python dicts are now ordered
#233Earlier quoted context omitted.
pretty strong evidence to the contrary https://apps.dtic.mil/dtic/tr/fulltext/u2/a627127.pdf do you have any references to back your claim that its actually faster?
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.
Re: Python dicts are now ordered
#234Earlier quoted context omitted.
I'm not clear on how this break existing code. Code that assumed it was arbitrary, would expect to handle any arbitrary order, including a happens-to-be sorted order. Code that assumed it was random, like actually inserted by random(), was already broken, because that simply isn't the case. Code that assumed the order would stay constant was relying on implementation-specific behavior, and could potentially break on…
It doesn’t break existing code. Code written for Python 3.7 might break on older versions of Python
Also, this change was implemented 3.6, but in 3.7 they officially documented it as a language feature (i.e. that all other Python implementations also need to preserve the order).
Re: Python dicts are now ordered
#235Earlier quoted context omitted.
That also goes both way: Pypy defaulted to ordered dicts a few years before cpython did.
The insertion order dict implementation actually comes from pypy
Re: Python dicts are now ordered
#236This is awesome, because the ordered map is the best data structure out there for easy & predictable programming, possibly only barring the array. There's so many cases where it's a benefit for map entries to retain order (and none where it's a problem). PHP really got this one right (and immediately messed it up by mixing ordered maps with arrays into a big soup, but hey, PHP). And so did, JS, sorta-kinda-by-acciden…
Re: Python dicts are now ordered
#237This is an amazing contribution to the language. A mixture of speed and convenience, probably made by volunteers. As for people criticizing a change to what use to be a non-deterministic ordering of a dict iteration; I don't know what to say to them, other than, are you serious? There are people out there who are working for us, they work for free and they did some heavy lifting to give us this. They might read what…
Other languages don't generally have special order guarantees about standard maps. This seems very idiosyncratic.
Re: Python dicts are now ordered
#238Earlier quoted context omitted.
What java calls linkedhashmap, Python calls ordereddict. It's not quite as old as java's linkedhashmap but is no spring chicken either (it's a bit above 10 years old).
Where's orderedset, though?
There are discussions on the subject on python-dev once in a while e.g. https://mail.python.org/pipermail/python-dev/2019-February/1...
Re: Python dicts are now ordered
#239Am I the only one that thinks this is a stupid decision? This will silently break code that starts to rely on this behaviour that gets executed on Python3.5 and lower. I would consider changing how a builtin works to be a major breaking change. It would have been fine if this was a change between 2 and 3 but on a minor version? Thats insane.
It's like, you have a great marriage with everything working out and some fine children who are doing great too, but you get a divorce anyway to pursue your dreams of being a conceptual artist.
(BTW, in case anyone is keeping track, I was going to maintain P2 but got caught up in Prolog, of all things, and now Python looks just as crude as everything else and I don't have the requisite love anymore to shoulder the work. I might make a Python 2 interpreter in Prolog though! That would be fun.)
Re: Python dicts are now ordered
#240Earlier quoted context omitted.
From the docs: "CPython implementation detail: Keys and values are listed in an arbitrary order which is non-random, varies across Python implementations, and depends on the dictionary’s history of insertions and deletions." So I would claim that equates to non-deterministic
I’d call undependable but maybe it’s the same thing in practice?