Dictionary print order


I am on step 8/13. Here is my code

prices = {"banana": 4, "apple": 2, "orange": 1.5, "pear": 3}

stock = {"banana": 6, "apple": 0, "orange": 32, "pear": 15}

for key in prices:
  print key
  print "price: %s" % prices[key]
  print "stock: %s \n" % stock[key]

Everything prints out correctly, but as you see below the order in odd. Could someone tell me why the order printed… Is the order printed. Why is orange first and pear second, etc.?

price: 1.5
stock: 32 

price: 3
stock: 15 

price: 4
stock: 6 

price: 2
stock: 0 

I see this question asked, but it has never been answered concretely to my understanding. If anyone could opine as to the logic I would appreciate it.


Dictionaries have no memory of the order of insertion so print in any order.


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