After my for loop successfully returns the keys of my first set of nested dictionaries. I am getting this error:
for item in MENU[drink][ingredient_list]:
TypeError: 'float' object is not iterable
I need to get access to all of the key-value pairs so that I can perform operations on them, but this code gets stuck at 'espresso'.
#3 levels deep nested dictionary
MENU = {
"espresso": {
"ingredients": {
"water": 50,
"coffee": 18,
},
"cost": 1.5,
},
"latte": {
"ingredients": {
"water": 200,
"milk": 150,
"coffee": 24,
},
"cost": 2.5,
},
"cappuccino": {
"ingredients": {
"water": 250,
"milk": 100,
"coffee": 24,
},
"cost": 3.0,
}
}
#level one of the dictionary
for drink in MENU:
#this should print the drinks and cost
print(drink)
#this should print the ingredients
for ingredient_list in MENU[drink]:
print(ingredient_list)
for item in MENU[drink][ingredient_list]:
print(item)