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.
Python dicts are now ordered
201–210 of 457 posts
Re: Python dicts are now ordered
#202This 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…
Re: Python dicts are now ordered
#203I'm glad to see other languages finally catching up to PHP. I'm joking (kind of) but after a lot of years of doing this, I've begun de-prioritizing pure abstractions and favoring the way that humans tend to do things on their own. Technically this is along the lines of the worse-is-better philosophy. The single biggest cost in software development is friction. Performance, size, etc are all less important, because th…
https://www.php.net/manual/en/language.types.array.php
Its pretty much the main data type used in php. Once you get used to it is pretty powerful for dynamic languages. They even have built in sorts:
https://www.php.net/manual/en/array.sorting.php
They are "simple arrays" that have numeric indexes, but I find those used less frequently. (They can morph into the key->value pair).
Re: Python dicts are now ordered
#204Earlier quoted context omitted.
Other languages don't generally have special order guarantees about standard maps. This seems very idiosyncratic.
Golang map iteration is returned in random order specifically to make sure that people don't rely on the order. I think this feature says a lot about the philosophy of Python vs Go.
Re: Python dicts are now ordered
#205Re: Python dicts are now ordered
#206This 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…
I was under the impression python dict ordering was deterministic, just not in an order recognisable by humans, i.e. ordered by hashes. Was this not the case?
So I would claim that equates to non-deterministic
Re: Python dicts are now ordered
#207Earlier quoted context omitted.
> 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 you wrote and think, "Why bother? Maybe I should spend my weekends playing with my kids instead." I don't agree…
As it’s widely known, more often than not “criticism” of open source software quickly devolves into hate and toxicity. Helpful criticism is great but be careful with defending the “criticism culture” around foss, it’s often angry unhappy people that want it all for free on a golden platter, and yesterday.
Re: Python dicts are now ordered
#208Earlier quoted context omitted.
I was under the impression python dict ordering was deterministic, just not in an order recognisable by humans, i.e. ordered by hashes. Was this not the case?
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
Re: Python dicts are now ordered
#209Earlier quoted context omitted.
> Code that ordered the dictionary keys before iterating are now slightly innefficient due to extra work of sorting a sorted list. Dicts are ordered , specifically insertion-ordered, not sorted . Sometimes they'll be sorted: D = {i:i for i in range(10)} ... specifically, when you insert them in sorted order. But then you can break the sortedness on your next insert: D[-1] = -1 What it allows is parallel iteration: zi…
The property you mention at the end has been true of dicts since long before 3.5, at least since 2.7 if not forever. See https://docs.python.org/2/library/stdtypes.html#dict.items : > If items(), keys(), values(), iteritems(), iterkeys(), and itervalues() are called with no intervening modifications to the dictionary, the lists will directly correspond. This allows the creation of (value, key) pairs using zip(): pair…
oldkeys = list(D.keys())
D[z] = foo(z)
now if you take zip(oldkeys, D.values())
then you're guaranteed to iterate over oldkeys, with the proper values associated with those keys -- if z was an oldkey, its value got updated; otherwise, it comes after oldkeys and gets dropped out of zip.The subtlety of this is what I, and perhaps others, find the most jarring.
Re: Python dicts are now ordered
#210No 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.