dict_keys不可订阅

时间:2017-07-20 17:38:29

标签: python dictionary

我是python的新手,我正在尝试使用字典编写代码,以确定竞赛获胜者的顺序。 (基本上是一种使用字典值的键)。 以下是我的代码:

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

以下是错误消息:

TypeError:'dict_keys'对象不可订阅

有人可以向我解释我做错了什么吗?据我所知,dictionary.keys()应该返回一个键列表,这些键应该是可订阅的。

0 个答案:

没有答案