11. New Entries - Using append with dictionaries



this was my code for this exercise:

menu = {} # Empty dictionary
menu['Chicken Alfredo'] = 14.50 # Adding new key-value pair
print menu['Chicken Alfredo']

menu["Fettucine"] = 13.50
menu["Penne"] = 9.25
menu["Bucatini"] = 22.48

print "There are " + str(len(menu)) + " items on the menu."
print menu


is there a way tidy up the code by using .append or .extend on a dictionary? i was thinking something along the lines of the following:

menu.extend{["Fettucine"] = 13.50, menu["Penne"] = 9.25, menu["Bucatini"] = 22.48}

this and variations of this did not work for me. i'm wondering what i am missing of if it is even possible.

Thank you!


Which exercise exactly?


We do know it is Python. so now we have at least narrowed it down.


@mtf @albionsrefuge


You could do this:

menu.update({'a':2.50, 'b':5.99, 'c':0.99})

See the update() part of the documentation here: https://docs.python.org/3/library/stdtypes.html#mapping-types-dict


Thank you so much. I'll give it try. Cheers!


That worked perfectly. Thank you so much!