from collections import OrderedDict
dictionary = {"Charlie": [[7]], "Alex": [[4]], "Brandon": [[8]]}
OrderedDict(sorted(dictionary.items(), key=lambda x: x[0]))
print(dictionary)
好吧我试图按字母顺序排序我的字典,但字典在第三行代码后没有更改顺序,如上所示。 任何人都可以帮我解决问题吗?如何按关键字按字母顺序排列字典
可能的重复[如何按字母顺序排序字典Python](http://stackoverflow.com/questions/22264956/how-to-sort-dictionary-by-key-in-alphabetical-order-python ) – alfasin 2015-01-20 19:26:26
也复制此:http://stackoverflow.com/questions/9001509/python-dictionary-sort-by-key(我其实更喜欢答案) – moooeeeep 2015-01-20 20:06:31