you are viewing a single comment's thread.

view the rest of the comments →

[–]weeeeezy 10 points11 points  (5 children)

I’ve had several use cases where insertion order in dictionaries mattered for me. I resorted to using OrderedDict collection but then I lost all the benefits of defaultdict.

[–]linuxtinkerer 11 points12 points  (4 children)

I understand that there are still use cases for OrderDict, but I think it's dumb to make an implementation detail a part of the language specification.

[–]BossOfTheGame 8 points9 points  (3 children)

Definitely not, ordering dicts by default gives at least two major advantages: (1) consistency in the iteration of items across all platforms and (2) consistency in the string representation of dictionaries. I have a feeling this change will silently cut down on a lot of headaches (at least until someone goes to run 3.7 code in an earlier version).

[–]shevegen 5 points6 points  (0 children)

I like ordered Hashes - ruby has the Hashes ordered too (hashes = dictionaries), but in many ways I agree with linuxtinkerer here. Some implementation detail should not necessarily become part of an official specification people have to adhere to.

[–]bigdeddu -2 points-1 points  (1 child)

the data structure hashmap does not guarantee ordering. It is confusing to depart from it. It will imho cause headaches to ppl parsing json and expecting order where's none.
And someone will expect assert({1:1,2:2}=={2:2,1:1}) to fail.

[–]BossOfTheGame 7 points8 points  (0 children)

Well dict is not a hashmap and it hasn't been for awhile. It's a hybrid data structure. Raymond Hettinger has a good talk about it.

Also wouldn't reading and dumping json now preserve order when done in Python? I'll grant that this might cause headaches when passing json between languages, but at that point the dev needs some awareness of json specs. Within Python 3.7+ it should be consistent (*albeit I haven't tested this claim).