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}
python3 sort 指定字典后的value值
最新推荐文章于 2022-02-25 16:45:13 发布
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}