Unique Features of OrderedDict in Python

By Pradyumna Chippigiri

February 16, 2026


Since Python 3.7, regular dict preserves insertion order. So why use OrderedDict? It has two features that dict still doesn't support.

1. move_to_end(key, last=True)

Move a key to the end (or beginning) in-place.

from collections import OrderedDict
 
od = OrderedDict([('a', 1), ('b', 2), ('c', 3)])
od.move_to_end('a')   # move 'a' to end
# OrderedDict([('b', 2), ('c', 3), ('a', 1)])
 
od.move_to_end('c', last=False)   # move 'c' to beginning
# OrderedDict([('c', 3), ('b', 2), ('a', 1)])

2. popitem(last=True)

dict.popitem() always removes the last inserted item (LIFO). OrderedDict.popitem(last=True) pops from the end; popitem(last=False) pops from the beginning, like a queue.

from collections import OrderedDict
 
od = OrderedDict([('a', 1), ('b', 2), ('c', 3)])
 
od.popitem()           # removes ('c', 3) — LIFO
od.popitem(last=False) # removes ('a', 1) — FIFO

LRU Cache: Real-world example

Here's an LRU Cache implementation using OrderedDict from LeetCode #146 — it uses both move_to_end and popitem(last=False):

LRU Cache solution using OrderedDict