python怎样把两个dictionary中的value相乘并相加?
python怎样把两个dictionary中的value相乘并相加?
如题,要把所有的价格和数量相乘再相加得到总价,然后再放到total中,最后面for那一段不太会写,(如果有错还望指出,
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]
total=0
for value in prices: