20 class OrderedDict(dict):
22 def __init__(self, order = None):
33 if self.__order
is not None:
36 return dict.keys(self)
39 return map(
lambda k, s = self: s[k], self.keys())
42 return map(
lambda k, s = self: (k, s[k]), self.keys())
45 return dict.__getitem__(self, self.__order[0])
53 def get_first_item(self):
56 value = dict.__getitem__(self, key)
60 def pop_first_item(self):
64 return key, self.pop(key)
68 value = dict.__getitem__(self, key)
74 def __setitem__(self, key, value):
76 if key
not in self.__order:
77 self.__order.append(key)
79 dict.__setitem__(self, key, value)
81 def __delitem__(self, key):
82 dict.__delitem__(self, key)
83 self.__order.remove(key)