python3 sort 指定字典后的value值

dic = {'a': 1, 'b': 3, 'c':2}
dic = {k: v for k, v in sorted(dic.items(), key=lambda item: item[1])}
print(dic)

==> {'a': 1, 'c': 2, 'b':3}

  

posted @ 2021-12-07 15:27   ̄□ ̄  阅读(41)  评论(0编辑  收藏  举报