Why not use collections.OrderedDict ? There are nice examples in doc: http://docs.python.org/3.3/library/collections.html?highlight=ordered#ordereddict-examples-and-recipes