I can't find it a Python documentation, although it exist at https://github.com/python/cpython/blob/3.6/Objects/odictobject.c
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 dict
s 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."