6 Comments
User's avatar
Wyrd Smythe's avatar

Interesting. I hadn't realized insertion order was formalized, though I've been using Python since two point something and sort of had noticed the change in behavior. Nice to know it's a property I can count on.

Expand full comment
Stephen Gruppetta's avatar

It makes standard dictionaries useable in more use cases, and there’s no drawback. Win-win

Expand full comment
Prince's avatar

Short and highly informative 👏 I think quick articles like this interspersed among the longer ones are a nice touch Stephen!

Expand full comment
Stephen Gruppetta's avatar

I'm planning to mix-and-match more between short and long, "traditional" and "narrative", and so on…

The next one is also short, and a follow up to this one (writing it now)

Expand full comment
Ash Roberts's avatar

I have a project I'm working on where I don't just need insertion order of the keys, I also need the index position of the keys. At first I thought that was something that OrderedDict was going to give me, but it doesn't have any methods for anything like that, so now I'm building my own dictionary class IndexedDict, that has an internal list to track the key position.

Expand full comment
Stephen Gruppetta's avatar

You could presumably build upon `OrderedDict` and use `list(self.keys())` to get a sequence of keys. Is that the route you’re taking?

Expand full comment