python 字典 按值排序

import sys
import os
print("Hello,World")

dic={'a': 4, 'b': 3, 'c': 2, 'd': 1}
result1 = sorted(dic.items(), key=lambda x: x[1])
result2 = sorted(dic.items(), key=lambda x: x[1],reverse=True)
print(result1)
print(result2)

猜你喜欢

转载自blog.csdn.net/u013288190/article/details/131525024