简体   繁体   中英

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?

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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