Simple exercise

Erik python at lucidity.plus.com
Thu Mar 10 04:38:46 EST 2016


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.



More information about the Python-list mailing list