The ___ data structure maps a key to a value.
map
dict
list
str
9 answers
dict
How would we determine if the item "tacos" was in a menu dict?
if "tacos":
# do something
if menu in "tacos":
# do something
if "tacos" in menu:
# do something
if in menu "tacos":
# do something
if "tacos":
# do something
if menu in "tacos":
# do something
if "tacos" in menu:
# do something
if in menu "tacos":
# do something
if "tacos" in menu:
# do something
# do something
What is the correct syntax to access the value (the taco's price) that the key "tacos" references in a menu dict?
taco_price = menu[tacos]
taco_price = menu{"tacos"}
taco_price = menu[taco_price]
taco_price = menu["tacos"]
taco_price = menu[tacos]
taco_price = menu{"tacos"}
taco_price = menu[taco_price]
taco_price = menu["tacos"]
taco_price = menu["tacos"]
Which line below shows how to loop through a menu dict's key/value pairs (the key is the menu item and the value is the price of the item)?
for price, item in menu.items():
# do something with the item and price
for item price in menu.items():
# do something with the item and price
for item, price in menu.items():
# do something with the item and price
for [item, price] in menu.items():
# do something with the item and price
for price, item in menu.items():
# do something with the item and price
for item price in menu.items():
# do something with the item and price
for item, price in menu.items():
# do something with the item and price
for [item, price] in menu.items():
# do something with the item and price
for item, price in menu.items():
# do something with the item and price
# do something with the item and price
How would you update the price of a taco to be 4.50 in a menu dict? Assume the key is the item name and the value is the item's price.
tacos[menu] = 4.50
menu[tacos] = 4.50
menu[4.50] = "tacos"
menu["tacos"] = 4.50
tacos[menu] = 4.50
menu[tacos] = 4.50
menu[4.50] = "tacos"
menu["tacos"] = 4.50
menu["tacos"] = 4.50