Two Dictionaries and a Sum!

Spacelee fjctlzy at gmail.com
Sat May 18 00:30:45 EDT 2013


for key in prices.keys():
    print prices[key]*stock[key]


On Sat, May 18, 2013 at 12:19 PM, Bradley Wright <
bradley.wright.biz at gmail.com> wrote:

> Confusing subject for a confusing problem (to a novice like me of course!)
> Thx for the help in advance folks
>
> I have (2) dictionaries:
>
> prices = {
>     "banana": 4,
>     "apple": 2,
>     "orange": 1.5,
>     "pear": 3
> }
>
> stock = {
>     "banana": 6,
>     "apple": 0,
>     "orange": 32,
>     "pear": 15
> }
>
> Here's my instructions:
>
> consider this as an inventory and calculate the sum (thats 4*6 = 24
> bananas!)
>
> HERES MY CODE:
>
> for key in prices:
>     print prices[key]*stock[key]
>
> HERES THE OUTPUT:
>
> 48.0
> 45
> 24
> 0
>
> ISSUE:
> I need to find a way to add all of those together...any pointers?
> --
> http://mail.python.org/mailman/listinfo/python-list
>



-- 
*Space Lee*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130518/aa9c077d/attachment.html>


More information about the Python-list mailing list