📌  相关文章
📜  如何按值对字典进行排序 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:54.355000             🧑  作者: Mango

代码示例1
dict1 = {1: 1, 2: 9, 3: 4}
sorted_dict = {}
sorted_keys = sorted(dict1, key=dict1.get)  # [1, 3, 2]

for w in sorted_keys:
    sorted_dict[w] = dict1[w]

print(sorted_dict) # {1: 1, 3: 4, 2: 9}