记录大佬sorted操作

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)

 

posted @ 2020-07-13 13:05  yin_zhaozhao  阅读(137)  评论(0编辑  收藏  举报