d={"a":3,"b":2}
print(sorted(d.items(),key=lambda x:x[1]))
实验结果:
"C:\Program Files\Anaconda3\python.exe" D:/pycharmprogram/learn/learn/dict_sorted.py
[('b', 2), ('a', 3)]Process finished with exit code 0
d.items是将字典转化成记录项。