11. making a purchase. (unhashable type list)


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):
for item in food:
total += prices[food]
return total

For whatever reason when I run this code it gives me the error "compute_bill(['apple']) resulted in a TypeError: unhashable type: 'list' for whatever reason.


You're using food which is a list as a key for a dictionary (prices), take a step back and ask yourself what it is you want to be doing at that line, which information should be involved and where is that information available?


inside your function you have to indent properly not in a same line
also item is your key not food


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.