Hacker News new | ask | show | jobs
by flafla2 1843 days ago
Funny, I just found out about this today.

Infuriatingly, this behavior is _not_ preserved for the set type.

2 comments

Yes that is because sets have their own hashmap implementation and the dev team remains so far unconvinced of the value of “unique lists”, and the primary gains of the new scheme might be nonexistent or of low impact for the set situation (for python the ordering properties were an ancillary change, not the reason for them))
I was just bitten by this the other day. In my case, it's not that I cared about any specific order ("unique lists"), but I did need the output to be deterministic for a caching mechanism to work properly. I knew dicts would 'just work' because of the ordering guarantee, but I was surprised to learn sets didn't. In the end the easiest fix was to just reimplement a set type on top of dict.
If you need an ordered set just use the time proven tradition of "poor man's set" in Python: (now ordered) dict keys