temp_dict = {"2": 2, "1": 1, "3": 3, "4": 4} temp = sorted(temp_dict.items(), key=lambda x: x[1], reverse=True) # 按照字典value降序排列 print(temp) #[('4', 4), ('3', 3), ('2', 2), ('1', 1)]
python 根据字典中value值大小进行排序
最新推荐文章于 2024-05-14 08:14:40 发布
temp_dict = {"2": 2, "1": 1, "3": 3, "4": 4} temp = sorted(temp_dict.items(), key=lambda x: x[1], reverse=True) # 按照字典value降序排列 print(temp) #[('4', 4), ('3', 3), ('2', 2), ('1', 1)]