Why is Python's OrderedDict ordered?

4 pointsposted 13 hours ago
by misonic

3 Comments

addaon

11 hours ago

Title of the article is "How…", not "Why…", and "why" is not discussed. (My understanding is that the "why" is "because the implementation acted that way without an official guarantee, and folks depended on the implementation detail, so it became guaranteed.)

DemocracyFTW2

9 hours ago

I don't think this is the "why". What you're depicting is what happened in JavaScript. Dictionary keys in Python always had that (to me) annoying property that they preserved insertion order until they don't. I'd frankly much prefer if they'd always be iterated in random order each time they're traversed.

DemocracyFTW2

9 hours ago

Wrong title, article has "How Does Python’s OrderedDict Maintain Order?"