How to add an element to the beginning of an OrderedDict?

There’s no built-in method for doing this in Python 2. If you need this, you need to write a prepend() method/function that operates on the OrderedDict internals with O(1) complexity. For Python 3.2 and later, you should use the move_to_end method. The method accepts a last argument which indicates whether the element will be moved … Read more

Will OrderedDict become redundant in Python 3.7?

No it won’t become redundant in Python 3.7 because OrderedDict is not just a dict that retains insertion order, it also offers an order dependent method, OrderedDict.move_to_end(), and supports reversed() iteration*. Moreover, equality comparisons with OrderedDict are order sensitive and this is still not the case for dict in Python 3.7, for example: >>> OrderedDict([(1,1), … Read more