prices = {
"banana": 4,
"apple": 2,
"orange": 1.5,
"pear": 3
}
stock = {
"banana": 6,
"apple": 0,
"orange": 32,
"pear": 15
}
for key in stock:
print key
print 'prince: %s' % prices[key]
print 'stock: %s' % stock[key]
The output when I run this code is as follows:
orange
prince: 1.5
stock: 32
pear
prince: 3
stock: 15
banana
prince: 4
stock: 6
apple
prince: 2
stock: 0
Why is it not printing according the order in which the elements appear in the dictionary? For example, why isn't 'banana' printed first, as follows:
banana
price: 4
stock: 6