Hi, everyone. I have a question regarding Python dictionary function.
We created a function that matches the following largest score - person names. I think it's recognized as 2,1 if the score is 20,19. Is there something wrong with the code?
The text file is shown below.
It's because the score is a string.
scores={}
result_f=open("./result.txt")
for line in result_f:
(name,score)=line.split()
print(type(score)) # <class 'str'>
score = int(score)
scores[score]=name
result_f.close()
print(scores)
for each_score in sorted(scores.keys(), reverse=True):
r = "Surfer: {0}, Scored: {1}".format(scores[each_score], each_score)
print(r)
© 2024 OneMinuteCode. All rights reserved.