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