def __setitem__(self, key, value):
    dict.__setitem__(self, key, value)
if key in self._order:
    self._order.remove(key)
self._order.append(key)

def __delitem__(self, key):
    dict.__delitem__(self, key)
self._order.remove(key)

def order(self):
    return self._order[:]

def ordered_items(self):
    return [(key, self[key]) for key in self._order]
od = ordered_dict()
od['hello'] = 'world'
od['goodbye'] = 'cruel world'
print(od.order())
del od['hello']
od['monty'] = 'python'
print(od.order())
od['hello'] = 'kitty'
print(od.order())
print(od.ordered_items())
How do you retrieve items from a dictionary in the order that they're inserted?