Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104496 > unrolled thread
| Started by | Erik <python@lucidity.plus.com> |
|---|---|
| First post | 2016-03-10 09:38 +0000 |
| Last post | 2016-03-10 09:38 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Simple exercise Erik <python@lucidity.plus.com> - 2016-03-10 09:38 +0000
| From | Erik <python@lucidity.plus.com> |
|---|---|
| Date | 2016-03-10 09:38 +0000 |
| Subject | Re: Simple exercise |
| Message-ID | <mailman.121.1457602735.15725.python-list@python.org> |
Hi. This looks a little like a homework problem, so I'll be cryptic ... :) On 10/03/16 09:02, Rodrick Brown wrote: >>From the following input > > 9 > BANANA FRIES 12 > POTATO CHIPS 30 > APPLE JUICE 10 > CANDY 5 > APPLE JUICE 10 > CANDY 5 > CANDY 5 > CANDY 5 > POTATO CHIPS 30 <snip> > if m: > if m.group(1) not in od.keys(): > od[m.group(1)] = int(m.group(2)) > else: > od[m.group(1)] += int(od.get(m.group(1),0)) Look very carefully at the last line above. What is it _actually_ doing? Also, consider that for each of the input lines all of the items that occur more than once exactly double the current value each time they are repeated. Except "CANDY", which is the item you are having a problem with ... that may tell you something. E.
Back to top | Article view | comp.lang.python
csiph-web