Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Erik Newsgroups: comp.lang.python Subject: Re: Simple exercise Date: Thu, 10 Mar 2016 09:38:46 +0000 Lines: 34 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de KvWzbzQVYir3eRts108lUAi4ce4iYyAy5sIsS+AZWu8Q== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.034 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'else:': 0.03; 'cryptic': 0.16; 'from:addr:python': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'something.': 0.16; 'wrote:': 0.16; 'input': 0.18; 'to:name:python-list@python.org': 0.20; 'to:2**1': 0.21; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'looks': 0.29; 'doing?': 0.29; 'problem': 0.33; 'subject:Simple': 0.33; "i'll": 0.33; 'except': 0.34; 'item': 0.35; 'skip:i 20': 0.36; 'lines': 0.36; 'apple': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'charset:windows-1252': 0.62; 'more': 0.63; 'carefully': 0.72; 'homework': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=Rr04V3SK c=1 sm=1 tr=0 a=X2VfThTz+8HMaRSzjuZh7Q==:117 a=X2VfThTz+8HMaRSzjuZh7Q==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=N659UExz7-8A:10 a=ZjWjHIIkauc0BM9oGe0A:9 a=pILNOxqGKmIA:10 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:104496 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 > 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.