The OrderedDict for Maintaining Insertion Order in Python


Before Python 3.7, OrderedDict was needed to maintain insertion order of dictionary keys.

Source Code

from collections import OrderedDict
od = OrderedDict()
od["c"] = 3
od["a"] = 1
od["b"] = 2
for key in od:
    print(key, od[key])
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments