python如何根据值排序一个字典【面试题详解】

今天爱分享给大家带来python如何根据值排序一个字典【面试题详解】,希望能够帮助到大家。


import operator
x = {1: 2, 3: 4, 4:3, 2:1, 0:0}
sorted_x = sorted(x.iteritems(), key=operator.itemgetter(1))
#[(0, 0), (2, 1), (1, 2), (4, 3), (3, 4)]
#dict(sorted_x) == x

原文链接:https://blog.itblood.com/4460.html,转载请注明出处。
0
绯色修仙录 V0.628 官方中文版 [PC/2.77G/更新] [RPG/动态/官中]
绯色修仙录 V0.628 官方中文版 [PC/2.77G/更新] [RPG/动态/官中]
5分钟前 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?