I'm new to python, and am trying to write code, using a dictionary, that can determine the order of the winners of a race. (Basically a sort of the keys using the values of the dictionary). The following is my code:
runners = {
str(input("Please put in name 1")):input("Please put in a number 1"),
str(input("Please put in name 2")):input("Please put in a number 2"),
str(input("Please put in name 3")):input("Please put in a number 3"),
}
def find_winner_name(dictionary):
winner_score = min(dictionary.values())
for i in dictionary.keys():
if winner_score == dictionary[dictionary.keys()[i]]:
return dictionary.keys()[i]
winnerName = find_winner_name(runners)
print(winnerName)#simply to make sure this is working so far
The following is the error message:
TypeError: 'dict_keys' object is not subscriptable
can somebody explain what I'm doing wrong to me? As far as I know, dictionary.keys() should return a list of keys, which should be subscriptable.