Not printing how I expect it to..... but still "successfully" completed this module


#1

On “A Day at the Supermarket” I got the following print out:

orange
price: 1.5
stock: 32
pear
price: 3
stock: 15
banana
price: 4
stock: 6
apple
price: 2
stock: 0
None

This is more or less correct but I expected the order of the print out to be “banana and price and stock” then “apple and price and stock” then “orange and price and stock” then “pear and price and stock”.

I’m not sure what is wrong, but below is my actual 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" % stock[key]

#3

Check out these questions on Stack Overflow. Hope this helps :slight_smile:

Stack Overflow random order?

In what order does python display dictionary keys?

Displaying in random order?


#4

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