我是 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
Run Code Online (Sandbox Code Playgroud)
以下是错误信息:
类型错误:“dict_keys”对象不可下标
有人可以解释一下我做错了什么吗?据我所知,dictionary.keys() 应该返回一个键列表,它应该是可下标的。
以下是我的linq表达式:
return from c in db.RecipeIngredients
join d in db.Ingredients on c.IngredientID equals d.IngredientsID
where c.RecipeID.Equals(recipeID)
select (d.IngredientsID,c.Unit,c.IngredientID,c.Amount).ToList();
Run Code Online (Sandbox Code Playgroud)
这应该返回成分信息行的列表。返回的类型是什么?现在如何继续使用firstRow.ingredientName等?