码迷,mamicode.com
首页 > 编程语言 > 详细

多字段指定不同方向排序

时间:2019-11-13 15:59:03      阅读:55      评论:0      收藏:0      [点我收藏+]

标签:lam   pytho   student   python   sort   for   class   code   weight   

students = [
    {'name':'a','score':'100','height':100,'weight':180},
    {'name':'b','score':'90','height':90,'weight':130},
    {'name':'c','score':'100','height':100,'weight':120},
    {'name':'d','score':'90','height':90,'weight':120},
    {'name':'e','score':'100','height':100,'weight':150},
    {'name':'f','score':'90','height':90,'weight':150},
]
l = sorted(students,key=lambda x:[x['score'] * -1,x['height'] * -1,x['weight']])

students.sort(key=lambda x: [x.get('score') * -1, x.get('height') * -1, x.get('weight')])
for i in students:
    print(i)
    
print('-'*99)
for i in l:
    print(i)

多字段指定不同方向排序

标签:lam   pytho   student   python   sort   for   class   code   weight   

原文地址:https://www.cnblogs.com/yunweixiaoxuesheng/p/11849695.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!