import UserDict class C(UserDict.UserDict): def __init__(self, initial): UserDict.UserDict.__init__(self,initial) self._positions = initial.keys() self._positions.sort() def __getitem__(self, index): if type(index) == type(0): index = self._positions[index] return UserDict.UserDict.__getitem__(self, index) c = C({'key1':'value1','key2':'value2'}) for i in c: print i