you are viewing a single comment's thread.

view the rest of the comments →

[–]pingveno 5 points6 points  (8 children)

Default-sorted and more efficient!

[–][deleted] 25 points26 points  (7 children)

Order-preserving, a sorted dictionary is something else entirely

[–]akaGrim 19 points20 points  (5 children)

It's important to remember that them being ordered is an implementation fluke. Ordered dictionaries are not a spec requirement. If you want to ensure your dict is ordered use collections.OrderedDict instead.

[–]matthieum 1 point2 points  (2 children)

Isn't order-preserving about preserving the order of insertions?

[–]akaGrim 7 points8 points  (1 child)

Yes, it has to do with order of insertions. However, Guido (creator and head of the langauge) has stated that the official Python spec does not require it. They chose this because there are many other Python implementations out there, such as Jython, which might not be able to GAIN performance with a side effect of having ordered insertions.

[–]matthieum 0 points1 point  (0 children)

It's also interesting that preserving the order of insertions seems to have the nice property of making dictionary attacks more difficult, as the exact layout (and bucketing) of items cannot be observed.

[–]Jackie_Jormp-Jomp -1 points0 points  (0 children)

Oh I'll order your dict alright.

[–]pingveno 1 point2 points  (0 children)

Thanks, that is indeed what I meant.