码迷,mamicode.com
首页 > 其他好文 > 详细

记录大佬sorted操作

时间:2020-07-13 13:23:29      阅读:60      评论:0      收藏:0      [点我收藏+]

标签:ptime   lse   span   lambda   code   false   step   记录   for   

dl = [
{
    "viewTimes": 236,
    "topTimes": 49,
    "stepsNum": 76,
    "collTimes": 321
},
{
    "viewTimes": 236,
    "topTimes": 47,
    "stepsNum": 58,
    "collTimes": 344
},
{
    "viewTimes": 238,
    "topTimes": 53,
    "stepsNum": 11,
    "collTimes": 321
},
{
    "viewTimes": 240,
    "topTimes": 31,
    "stepsNum": 39,
    "collTimes": 344
},
{
    "viewTimes": 240,
    "topTimes": 38,
    "stepsNum": 13,
    "collTimes": 200
}]
# 按viewTimes升序排列,再按stepsNum升序排列
# dl2 = sorted(dl, key=lambda obj: (obj[‘viewTimes‘], obj[‘stepsNum‘]), reverse=False)

# 按viewTimes升序排列,再按stepsNum降序排列
dl2 = sorted(dl, key=lambda obj: (obj[viewTimes], -obj[stepsNum]), reverse=False)
dl_tmp[stepsNum], reverse=False)
print(dl2)
for temp in dl2:
    print(temp)

 

记录大佬sorted操作

标签:ptime   lse   span   lambda   code   false   step   记录   for   

原文地址:https://www.cnblogs.com/Vera-y/p/13292679.html

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