zoukankan      html  css  js  c++  java
  • python list排序


    data_list = []
    data_list.append({'softname':'1','version':'1.2.2.2'})
    data_list.append({'softname':'7','version':'1.2.2.2'})
    data_list.append({'softname':'5','version':'1.2.2.2'})
    data_list.append({'softname':'2','version':'1.2.2.2'})
    data_list.append({'softname':'3','version':'1.2.2.2'})
    data_list.append({'softname':'9','version':'1.2.2.2'})
    #升序
    data_list.sort(key=lambda obj:obj.get('softname'), reverse=False)

    print data_list
    #[{'softname': '1'}, {'softname': '2'}, {'softname': '3'}, {'softname': '5'}, {'softname': '7'}, {'softname': '9'}]
    #降序
    data_list.sort(key=lambda obj:obj.get('softname'), reverse=True)
    print data_list
    #[{'softname': '9'}, {'softname': '7'}, {'softname': '5'}, {'softname': '3'}, {'softname': '2'}, {'softname': '1'}]

  • 相关阅读:
    TreeMap
    索引
    B-树、B+树
    硬盘速度、存储方式
    2-3树
    多叉树、2-3-4树
    红黑树
    平衡树、AVL树
    树、多路树、二叉树
    Java实现后缀表达式建立表达式树
  • 原文地址:https://www.cnblogs.com/lhj588/p/2470223.html
Copyright © 2011-2022 走看看