11. New Entries - Why randomly print out menu


#1

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

Your code here: Add some dish-price pairs to menu!

menu['Spam'] = 2.50
menu['Pasta'] = 11.00
menu['Burn'] = 4.50

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

RESULT

14.5
There are 4 items on the menu.
{'Pasta': 11.0, 'Chicken Alfredo': 14.5, 'Burn': 4.5, 'Spam': 2.5}
None


Why randomly print out menu components?

I added Chicken Alfredo firstly, Spam secondly, Pasta thirdly, and Burn fourthly.

Plz, tell me why

Thanks.


#2

Hello, @seunghyeonlee!
Different from lists, dictionaries don't follow the order you write them.
Even if you wrote everything alphabetically, whenver you print them they'll show up in different "positions".

If it was {"A":2, "B":3} it can either be printed the same way it is or {"B": 3, "A": 2}.