1. 列表排序,列表元素是字典,按照字典的某个元素排序:
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)
#降序
data_list.sort(key=lambda obj:obj.get('softname'), reverse=True)2. 列表排序,列表的元素是元组,按照元组的某个成员排序
data_list = []
data_list.append(1,{'version':'1.2.2.2'})
data_list.append(7,{'version':'1.2.2.2'})
data_list.append(5,{'version':'1.2.2.2'})
data_list.append(2,{'version':'1.2.2.2'})
data_list.append(3,{'version':'1.2.2.2'})
data_list.append(9,{'version':'1.2.2.2'})
#升序
data_list.sort(key=lambda item:item[0], reverse=False)
#降序
data_list.sort(key=lambda item:item[0], reverse=True)