0

I can't find it a Python documentation, although it exist at https://github.com/python/cpython/blob/3.6/Objects/odictobject.c

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
GM1
  • 380
  • 3
  • 14

1 Answers1

0

The page you refer to is a C implementation of the OrderedDict class. But if you are programming in Python, not C, all you need to do is import the Python implementation from the collections library module:

from collections import OrderedDict
mydict = OrderedDict()

I'm a little puzzled that you would want to use the C implementation in a Python program.

And, in any case, from Python 3.6, normal dicts in Python also preserve input order, which means there is now little reason to use an OrderedDict in new code. Raymond Hettinger (who wrote the OrderedDict class) tweeted in September 2016 "OrderedDict is dead. Long live dicts that are ordered."

BoarGules
  • 16,440
  • 2
  • 27
  • 44
  • Thanks a lot for your answer. I wanted to pass ordered dictionary from C to Python, so the end of your answer shows it's already embedded at the regular Dict, and that explains why I couldn't find it at Python documentation. – GM1 Jan 21 '19 at 08:50