Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #104496

Re: Simple exercise

From Erik <python@lucidity.plus.com>
Newsgroups comp.lang.python
Subject Re: Simple exercise
Date 2016-03-10 09:38 +0000
Message-ID <mailman.121.1457602735.15725.python-list@python.org> (permalink)
References <CABRP1o-c+Y7U9owb7_g9WU71FjNo6GT7XVhcuQqgasMrsv2GtA@mail.gmail.com>

Show all headers | View raw


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 comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Simple exercise Erik <python@lucidity.plus.com> - 2016-03-10 09:38 +0000

csiph-web