Complete beginner here, I am currently doing an exercise where I have to make Python read a text file with countries and scores and then I need to print the highest score first until the lowest score.
So for example a text file could look like the following:
Canada 14
Brazil 9
South Korea 16
(There are many other additional text files with different scores, but I start with the first one)
My code until now:
firstscoredocument = f.readlines()
for line in firstscoredocument:
nums_str = line.split()[1:]
nums = [int(n) for n in nums_str]
max_in_line = max(nums)
print max_in_line
This code prints
14
9
16
I would need it to print
South Korea 16
Canada 14
Brazil 9
Also, I can't seem to find a way how to print them from highest to lowest...
Can anyone give me a hint please?
thank you very much :)