简体   繁体   English

行距不起作用

[英]Line spacing not working

How can I get each player name with its average score on a separate lines, my code is: 如何获得每个球员的名字及其平均分数,我的代码是:

print(sorted(player_averages.items(), key=lambda x: x[1])

I have tried \\n but doesn't work, are there any other creative ways in which this can be achieved? 我尝试了\\n但没有用,是否还有其他创造性的方法可以实现?

Just use a loop to print your players: 只需使用循环来打印您的播放器:

for name, average in sorted(player_averages.items(), key=lambda x: x[1]):
    print(name, average)

To do it on one line, you'll need to use a generator expression formatting each name-average pair: 为此,您需要使用一个生成器表达式来格式化每个名称平均对:

print(*('{}: {}'.format(name, average)
        for name, average in sorted(player_averages.items(), key=lambda x: x[1]),
      sep='\n')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM