Live data from Hacker News

Python dicts are now ordered

softwaremaniacs.org

231–240 of 457 posts

Re: Python dicts are now ordered

#231
post #158

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.

If I remember correctly his talk. He went to CPython first and it was rejected, but PyPy welcomed it.

Re: Python dicts are now ordered

#232
post #218

Earlier 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?

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

#233

Earlier 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.

Good link, thanks

Re: Python dicts are now ordered

#234
post #20

Earlier 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

Well... full support for 3.6 ended in December of 2018 (now it only has security fixes), the older versions are already unsupported.

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

#235
post #193

Earlier 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

The insertion order dict implementation comes from Raymond Hettinger who is amongst other things a core CPython developer. pypy pulled the trigger on using it first (and probably has optimisations CPython doesn't). PHP also used it before CPython did, IIRC. And possibly Rust (as the third-party indexmap).

Re: Python dicts are now ordered

#236

This 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…

>1)

https://stackoverflow.com/questions/30076219/does-es6-introd...

Re: Python dicts are now ordered

#237
post #164

This 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.

In regards to sibling replies, does it feel to anyone else like everything (except golang) is converging towards PHP's array() ?

Re: Python dicts are now ordered

#238

Earlier 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?

Nowhere because so far the core team has remained unconvinced. People have brought up replacing standard set implementation by a variant of dict's (even expressing surprise that that wasn't already the case) but no dice yet.

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

#239
post #15

Am 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.

No, I agree, it's stupid. To me it feels like a kind of conceptual backwash from JS. The whole P3 fiasco looks really silly from far enough away.

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

#240
post #208

Earlier 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?

That's generally what people mean when they say "nondeterministic" in the context of computing. Yeah, in philosophy it generally means something like "the future is not completely determined by the past," but in computing it means something closer to "the programmer cannot reasonably determine the behavior and thus should not depend on specific behavior."
Post reply on HN