# Function's argument should be a list or a dict?

#1

I am puzzled...I get this error message "Oops, try again. calling compute_bill with a list containing 1 apple, 1 pear and 1 banana caused the following error: list indices must be integers, not str"

In the instructions it the function should have the argument "food" list, where as for the function to take both the type of food, and the quantity, it seems it should be a dictionary.

I do understand in the equation, total = total + food[key]*prices[key], since "key" is a string, hence the error. My problem is I can't figure out where the quantity of food items we want to buy, and how they get into the function's argument if it is only a list - is the list just numbers in the order of the "stock" dictionary items?

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 key in food:
if stock[key] > 0:
total = total + food[key]*prices[key]
stock[key] -= stock[key]

#2

['apple', 'apple', 'apple']

#3

OK. I got it. But, my code is still not calculating correctly...help please.

def compute_bill(food):
total = 0
for item in food:
if stock[item] > 0:
total += prices[item]
stock[item] -= stock[item]