13/37
Part 3 of 6 · OrderedDictLearn and do

OrderedDict gives you the same order in a few lines

Python already ships a dict that keeps an order you can change.

With the newest on the right, move_to_end marks a use and popitem(last=False) evicts the oldest

from collections import OrderedDict

d = OrderedDict.fromkeys("abc")
d["a"] = 10
print(list(d))
d.move_to_end("a")
print(list(d))
print(d.popitem(last=False))
print(d.popitem())
Predict

popitem() with no argument: which end of the OrderedDict does it take?

Pick one to see what it prints.
Pick an answer above to see the rest
Predict

This OrderedDict put stores the new key first and evicts after. Which test decides that it must evict?

Pick an answer above to see the rest