美文网首页
字典根据value值排序

字典根据value值排序

作者: 隐墨留白 | 来源:发表于2019-03-26 15:40 被阅读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']
    

    相关文章

      网友评论

          本文标题:字典根据value值排序

          本文链接:https://www.haomeiwen.com/subject/wyagvqtx.html