如何解决如何使用排序函数discord.py?
我使用以下代码制作一张积分表:
@bot.command()
async def start(ctx):
await ctx.send("How many total teams are there?")
t = await get_input_of_type(int,ctx)
embed = discord.Embed(title="**__Today's Result:__**",color=0x03f8fc)
lst = []
for i in range(t):
await ctx.send(f"Enter team {i+1} name :")
teamname = await get_input_of_type(str,ctx)
await ctx.send("How many kills did they get?")
firstnum = await get_input_of_type(int,ctx)
await ctx.send("How much Position points did they score?")
secondnum = await get_input_of_type(int,ctx)
lst.append((teamname,firstnum,secondnum)) # append to results
lstSorted = sorted(lst,key = lambda x: int(x[1]) + int(x[2])) # sort results by kills + points
for teamname,secondnum in lstSorted: # process embed
embed.add_field(name=teamname,value=f'Kills: {firstnum}\nPosition Pt: {secondnum}\nTotal Pt: {firstnum+secondnum}',inline=False)
await ctx.send(embed=embed)
问题是代码可以很好地工作,但是我希望它根据总点将结果排序为降序,但这是行不通的,我不知道我在这里做错了什么。
如果您能为我提供一些更好的结果可视化建议,也非常欢迎。 谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。