| ▲ | zahlman 2 days ago | |||||||||||||||||||||||||||||||
> Ordering, like stability in sorting, is an incredibly useful property. I can't say I've noticed any good reasons to rely on it. Didn't reach for `OrderedDict` often back in the day either. I've had more use for actual sorting than for preserving the insertion order. | ||||||||||||||||||||||||||||||||
| ▲ | mcherm 2 days ago | parent | next [-] | |||||||||||||||||||||||||||||||
Personally, I find lots of reasons to prefer an orders Dict to an unordered one. Even small effects like "the debugging output will appear in a consistent order making it easier to compare" can be motivation enough in many use cases. | ||||||||||||||||||||||||||||||||
| ▲ | xen0 2 days ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
It's sometimes nice to be deterministic. I don't often care about a specific order, only that I get the same order every time. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | morshu9001 2 days ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Same. Recently I saw interview feedback where someone complained that the candidate used OrderedDict instead of the built-in dict that is now ordered, but they'll let it slide... As if writing code that will silently do different things depending on minor Python version is a good idea. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | vanviegen 2 days ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Indeed! I don't understand why it isn't more common for stdlibs to include key-ordered maps and sets. Way more useful than insertion ordering. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | kzrdude 2 days ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
It seems like opinions really differ on this item then. I love insertion sort ordering in mappings, and python with it was a big revelation. The main reason is that keys need some order, and insertion order -> iteration order is a lot better than pseudorandom order (hash based orders). For me, it creates more reproducible programs and scripts, even simple ones. | ||||||||||||||||||||||||||||||||
| ▲ | BiteCode_dev 2 days ago | parent | prev [-] | |||||||||||||||||||||||||||||||
Ordering is very useful for testing. This morning for example, I tested an object serialized through a JSON API. My test data seems to never match the next run. After a while, I realized one of the objects was using a set of objects, which in the API was turned into a JSON array, but the order of said array would change depending of the initial Python VM state. 3 days ago, I used itertools.group by to group a bunch of things. But itertools.group by only works on iterable that are sorted by the grouping key. Now granted, none of those recent example are related to dicts, but dict is not a special case. And it's iterated over regularly. | ||||||||||||||||||||||||||||||||