找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2373|回复: 1

[求助] Sorted函数的组成看不懂尤其是下面这个程序,求大佬解答

1

主题

1

帖子

1

积分

贫民

积分
1
fengdou111 发表于 2022-8-4 03:02:00 | 显示全部楼层 |阅读模式

# 电视剧信息列表 每条信息包含收视率信息
TV_plays=[('Give uphold on to me',1.4),
          ('The private dishes of the husbands',1.343),
          ('My father-in-law will do martiaiarts',0.92),
          ('North Canton still believe in love',0.862),
          ('Impossible task',0.553),
          ('Sparrow',0.411),
          ('East of dream Avenue',0.164),
          ('Theprodigal son of the new frontier town',0.259),
          ('Distant distance',0.394),
          ('Music legend',0.562),
          ]
# 使用内置srted方法进行降序排序
TV_plays=sorted(TV_plays, key=lambda s: s[1], reverse=True)
print('电视剧的收视率排行榜:')
# 循环输出电视剧信息
for TV_play in TV_plays:
  print(TV_play[0]+' 收视率:'+str(TV_play[1])+'%')

里面的s: s[1]有大佬能解释一下吗?
回复

使用道具 举报

0

主题

956

帖子

956

积分

圣骑士

积分
956
sheeboard 发表于 2022-8-24 19:02:29 | 显示全部楼层
本帖最后由 sheeboard 于 2022-8-24 19:29 编辑

s[1]是key,也就是每行数据的第二个收视率。lambda是隐函数相当与def get_second(s):   return s[1]
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表