字典根据value值排序

2019-03-26  本文已影响0人  隐墨留白
person = {"li":18,"wang":50,"zhang":20,"sun":22}

person_age_min = min(person, key=person.get)
print(person_age_min)
person_age_max = max(person, key=person.get)
print(person_age_max)
person_sort = sorted(person, key=person.get)
print(person_sort)
person_re_sort = sorted(person, key=person.get,reverse=True)
print(person_re_sort)

#运行结果
li
wang
['li', 'zhang', 'sun', 'wang']
['wang', 'sun', 'zhang', 'li']
上一篇 下一篇

猜你喜欢

热点阅读