import collections dicionario_ordenado = collections.OrderedDict(sorted_x)