Reputation: 1780
I'm curious as to how OrderedDict from the collections library keeps key/pair order? I looked around online and couldn't find an answer.
Upvotes: 6
Views: 1089
Reputation: 3279
From the source code, it appears to be implemented as a dict
with a doubly linked list of keys for ordering, as well as another dict
that maps keys to their position in the list.
Upvotes: 8