OrderedDict Initialization
An OrderedDict is a Python dict which remembers insertion order. When iterating over an OrderedDict, items are returned in that order. Ordinary dicts return their items in an unspecified order.
Ironically, most of the ways of constructing an initialized OrderedDict end up breaking the ordering in Python 2.x and in Python 3.5 and below. Specifically, using keyword arguments or passing a dict (mapping) will not retain the insertion order of the source code.
Python 2.7.13 (default, Dec 18 2016, 07:03:39) >>> from collections import OrderedDict >>> odict = OrderedDict() >>> odict['one'] = 1 >>> odict['two'] = 2 >>> odict['three'] = 3 >>> odict['four'] = 4 >>> odict['five'] = 5 >>> odict.items() [('one', 1), ('two', 2), ('three',…continue.