5

OrderedDict is a collection that preserves order of items (in which they were inserted). I do not think this can be achieved with hashtables (which regular dict uses I think) so are balanced trees used to implement it?

I assume there are many depends like Python 2/3 and CPython/IPython/others.

ArekBulski
  • 3,796
  • 2
  • 31
  • 52

1 Answers1

25

You can read the implementation in CPython's source code: Lib/collections/__init__.py as OrderedDict is implemented in Python.

It uses a doubly linked list to maintain the order of the elements in the dictionary.

Boris Verkhovskiy
  • 10,733
  • 7
  • 77
  • 79
Simeon Visser
  • 113,587
  • 18
  • 171
  • 175