一种字典排序方法

1.基于python3.6

words_dict = {}
words_dict["周一"] = 3
words_dict["周二"] = 5
words_dict["周三"] = 10
words_dict["周四"] = 7
words_dict["周五"] = 1
# 根据键的值倒叙排序
all_words_tuple_dict = sorted(words_dict.items(), key=lambda f: f[1], reverse=True)
print(all_words_tuple_dict)
all_words_list, all_words_nums = zip(*all_words_tuple_dict) # 解压缩
all_words_list = list(all_words_list)
all_words_nums = list(all_words_nums)
print(all_words_list)
print(all_words_nums)

2.运行结果
一种字典排序方法_第1张图片

你可能感兴趣的:(Python)