Starting with Python 3.7 , a new improvement:
the nature of preserving the insertion order of dict objects has been declared an official part of the Python language specification.
This means there is no longer a need for an OrderedDict. They are almost the same. But there are differences that are worth paying attention to.
from collections import OrderedDict d = {'b': 1, 'a': 2} od = OrderedDict([('b', 1), ('a', 2)])
Obviously, there is a difference between the string representation of two objects, with the dict object in a more natural and compact form.
As for the various methods between them, this question can be answered using set theory:
d_set = set(dir(d)) od_set = set(dir(od)) od_set.difference(d_set) # {'__dict__', '__reversed__', 'move_to_end'}
This means that OrderedDict has at least two functions that do not have a built-in dict , but workarounds are shown here:
# 1) OrderedDict can be reversed (but then what?) reversed(od)
source share