I am a computer science student and for my GCSE course we need to complete a NEA course.
I chose the task where we make a dice game and I am stuck on a bit where I sort a dictionary into the top 5 scores.
My code reads a leaderboards.txt and converts it to a dictionary. Below is Leaderboard.txt
12 p2
13 p1
1412 p5
34 p3
213 p6
9 p4
And now I cant find anywhere which tells me how I can sort a dictionary by the top values. Below is my code
highscores={}
with open("Leaderboard.txt") as f:
for line in f:
(key,val) = line.split(" ")
highscores[int(key)] = val
How can I print top 5 values in the dict? Thanks