关于字典的排序
如果字典是随机的,即非公共键。
a={"james":23,"wade":3,"bosh":1,"yaoming":11}
字典是由key和values组成,如果想要排出数字最多的values。
max(a(zip(a.values(),a.keys()))
如果是公共键,比如类似球员的号码,现在要列出最大的号码所在的字典
b=[
{"name"="james","num"=23"},
{"name"="wade","num"=3},
{"name"="bosh","num"=1},
{"name"="yaoming","num"=11}
]
from operator import itemgetter
max(b,key=itemgetter("num"))
本文出自 “生活就是等待戈多” 博客,请务必保留此出处http://chenx1242.blog.51cto.com/10430133/1778592
原文地址:http://chenx1242.blog.51cto.com/10430133/1778592