如果字典是随机的,即非公共键。
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"))
时间: 2024-10-07 13:04:50