logoalt Hacker News

jonathaneunicelast Thursday at 1:52 PM3 repliesview on HN

Ordering, like stability in sorting, is an incredibly useful property. If it costs a little, then so be it.

This is optimizing for the common case, where memory is generally plentiful and dicts grow more than they shrink. Python has so many memory inefficiencies that occasional tombstones in the dict internal structure is unlikely to be a major effect. If you're really concerned, do `d = dict(d)` after aggressive deletion.


Replies

zahlmanlast Thursday at 2:09 PM

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

show 6 replies
seanhunterlast Thursday at 4:08 PM

Ordering is specifically a property (useful or not) that a set doesn't have. You need a poset for it to be ordered.

I would expect to use a different data structure if I needed an ordered set.

LtWorflast Thursday at 3:57 PM

Does your code actually rely on that? I've never once needed it.