我很难理解下面代码的一部分。我能够在在线课程中正确理解它,所以我不是在寻求帮助来完成它,只是理解这一点:在最后一段代码中,我对x和food的工作方式感到困惑。x 如何处理价格中的项目?
shopping_list = ["banana", "orange", "apple"]
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
def compute_bill(food):
total = 0
for x in food:
total = total + prices[x]
return total