I have a program that reads the top 5 (or all scores and usernames if there are less than 5 people on the leaderboard of a .csv file, called leaderboard2.csv.
However, in the python shell it says this:
Here is the Top 5 leaderboard:
Username - Score
123 - 74
example - 45
ok - 36
sample - 36
testing - 30
I would like to say 1st place, or 2nd place, so on next to each of the lines above in the shell. E.g. 2nd Place = example - 45.
How do I display it like above (When I do it, it is completely wrong as it displays everyone in the leaderboard next to "1st place = ")
Im using python 3.3.4 by the way.
Thanks in advance, here is my code below:
import csv
from collections import Counter
scores = Counter()
with open('leaderboard2.csv') as f:
for name,score in csv.reader(f):
# convert score into integer
score = int(score)
scores[name] = score
# list the top five
print("Here is the Top 5 leaderboard:")
print("Username - Score")
print("")
for name, score in scores.most_common(5):
print(name + " - " + str(score))