简而言之,我正在制作一个程序,用户可以在其中添加食谱,但我遇到了以下代码的问题:
TypeError: list indices must be integers or slices not list
for things in ingredients:
recipe.append(ingredients[things])
在这种情况下,配方看起来像这样:
recipe = [["name", "cake"], ["amount", 2]]
成分将是
[["eggs", 12], ["flour", 500]]
我想要做的只是将每个嵌套数组从“成分”添加到“食谱”,这只是我能想到的最简单的事情——我知道如何用字典或 while 循环以不同的方式做到这一点,但是我只是想知道为什么这会导致错误。