美文网首页
字典根据Key排序

字典根据Key排序

作者: 地雷 | 来源:发表于2020-05-22 17:29 被阅读0次
    value_dict = {"value24":"0.26",
                  "value65":"0.24",
                  "value89":"4.25",
                  "value12":"1.25",
                  "value1":"0.25",
                  "value67":"2.45",
                  "value2":"0.65",
                  "value556":"9.25",
                  "value1234":"0.15",
                  "value123":"0.95",
                  "value21":"0.25",
                  "value89":"0.28",
                  "value2":"0.29",
                  "value6":"0.75"}
    
    print sorted(value_dict, key=lambda x:int(x[5:])+1)
    print sorted(value_dict.items(), key=lambda key:int(key[0][5:]))
    

    相关文章

      网友评论

          本文标题:字典根据Key排序

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