Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45491
| References | <6012d69f-b65e-4d65-90c4-f04876853f5e@googlegroups.com> |
|---|---|
| Date | 2013-05-18 12:30 +0800 |
| Subject | Re: Two Dictionaries and a Sum! |
| From | Spacelee <fjctlzy@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1792.1368851449.3114.python-list@python.org> (permalink) |
[Multipart message — attachments visible in raw view] - view raw
for key in prices.keys():
print prices[key]*stock[key]
On Sat, May 18, 2013 at 12:19 PM, Bradley Wright <
bradley.wright.biz@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*
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Two Dictionaries and a Sum! Bradley Wright <bradley.wright.biz@gmail.com> - 2013-05-17 21:19 -0700 Re: Two Dictionaries and a Sum! Spacelee <fjctlzy@gmail.com> - 2013-05-18 12:30 +0800 Re: Two Dictionaries and a Sum! nanobio <hektorlg@gmail.com> - 2013-05-17 22:20 -0700 Re: Two Dictionaries and a Sum! nanobio <hektorlg@gmail.com> - 2013-05-17 22:22 -0700 Re: Two Dictionaries and a Sum! Chris Angelico <rosuav@gmail.com> - 2013-05-18 15:10 +1000 Re: Two Dictionaries and a Sum! Roy Smith <roy@panix.com> - 2013-05-18 09:22 -0400
csiph-web