Something of Value


#1


Replace this line with your code. Do not remove the backticks that are above or below this line.


prices = {
"banana" : 4,
"apple" : 2,
"orange" : 1.5,
"pear" : 3,
}
stock = {
"banana" : 6,
"apple" : 0,
"orange" : 32,
"pear" : 15,
}
total = 0
for key in prices:
print key
print "price: %s" % prices[key]
print "stock: %s" % stock[key]
total = 0
for x in prices:
total += prices[x] * stock[x]
print total

who can tell me why at the last prices[key] is apple's key?


#2

@seven7z,

Dictionaries have no order in python.

Have a read through
http://stackoverflow.com/questions/11784860/why-does-this-python-dictionary-get-created-out-of-order-using-setdefault