Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #104561
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Simple exercise |
| Date | Fri, 11 Mar 2016 10:38:01 +1100 |
| Lines | 20 |
| Message-ID | <mailman.160.1457653085.15725.python-list@python.org> (permalink) |
| References | <mailman.117.1457600573.15725.python-list@python.org> <dkee0qF5s1dU1@mid.individual.net> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de oUCl26iTtL+KSt2U2u3hgg2t2pqFOKQEC596fCLLAHQg== |
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.005 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'cc:addr :python-list': 0.09; '0))': 0.09; 'meaningful': 0.09; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'gregory': 0.16; 'received:209.85.213.176': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'names.': 0.22; 'am,': 0.23; "haven't": 0.24; 'second': 0.24; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'right.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'anywhere': 0.30; 'code': 0.30; 'instead,': 0.33; 'subject:Simple': 0.33; 'case,': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'replaced': 0.35; 'something': 0.35; "isn't": 0.35; 'should': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'doing': 0.38; 'received:209': 0.38; 'mar': 0.65; 'chrisa': 0.84; 'to:none': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=l7rQcQ/y6+bu4i5nMs0GVy7khXIEl28hw8Q1/xaqgZs=; b=F/Tnpkhd+0Lk1kLOK1WXyGBN9lFoYn/jNTFvFIGbhKKwWH7dAnPDABwESqNRkwIPVw iGr0A9IL3IUHfaEfI9mdTYTrjfVm9OE2b/FsOyI9yWhlRPwC91iFyaw2DV4C03ry2smh WhjnvvWFDcmVa0LNR2JDeXKYAGJi0dL+reNr/QkjS5oQhvcaerE8uMsrEtAaqafukn0j IElQhkhWIl6yFdqwJXhFKqE3Q4rjafqi090jTQQ0MSM+ogRMHcTfIBJz34eSpKYFepxz CKO9dZynW5xn7Kjl7m66uQlilzWV8kLkFvuNaxzOx+DNsBs7sdpZcfbBTZN4SKrNJft6 9qew== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=l7rQcQ/y6+bu4i5nMs0GVy7khXIEl28hw8Q1/xaqgZs=; b=Re+icQD5yk3dBYz3Tya5U+jdz0YBckpUBhJ3IAVrRXOpMEOmFecfPqoolfGU7ft9v6 V+rX66MgC8i60Mx6VEWNd2WDUlO3XSr5eaarPiIrO3hbz4A11HwvpOt9ZaLXZGoULfpn wqQSf2K3jSJdOxR8OBsvi1M1Ifmw4MpEhVCN7jTR4kACr5UHXydYlC4UV4Y9sWFiWww6 kNdvpuJ/VrMAiR2GqEstqS1gEfESYixQYfZb+Lib4FqamRtD4qtNLFEhXuWC8n6ktoOz fX4zcSk4RZNI11B8P8GbPT8Gp9W8yFERSFkHyplOYgp73Hoasba8iIaXoa+7p0oLuAgm wpng== |
| X-Gm-Message-State | AD7BkJJO/v9+SEvdn6lRD7x4fJxFQF9wP5M9CgwR2vPpeU3iw5/E3mcKPo9N2InmbBhxsaw9NNiRiEqQ2Ge9pA== |
| X-Received | by 10.50.137.35 with SMTP id qf3mr1083303igb.92.1457653081471; Thu, 10 Mar 2016 15:38:01 -0800 (PST) |
| In-Reply-To | <dkee0qF5s1dU1@mid.individual.net> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Xref | csiph.com comp.lang.python:104561 |
Show key headers only | View raw
On Fri, Mar 11, 2016 at 10:24 AM, Gregory Ewing <greg.ewing@canterbury.ac.nz> wrote: > Instead, pull them out and give them meaningful names. > Doing so with the above code gives: > > name = m.group(1) > value = m.group(2) > if name not in od.keys(): > od[name] = int(value) > else: > od[name] += int(od.get(name, 0)) > > Now it's a lot eaier to see that you haven't used the > value anywhere in the second case, which should alert > you that something isn't right. Although in this case, the code is majorly redundant - and could be replaced entirely with a defaultdict(int). ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Simple exercise Rodrick Brown <rodrick.brown@gmail.com> - 2016-03-10 04:02 -0500
Re: Simple exercise Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-10 11:30 +0100
Re: Simple exercise Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-10 12:07 +0100
Re: Simple exercise Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-10 17:05 +0100
Re: Simple exercise Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-03-10 17:08 +0100
Re: Simple exercise Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2016-03-11 12:24 +1300
Re: Simple exercise Chris Angelico <rosuav@gmail.com> - 2016-03-11 10:38 +1100
Re: Simple exercise BartC <bc@freeuk.com> - 2016-03-11 00:05 +0000
Re: Simple exercise Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-11 01:21 +0000
Re: Simple exercise BartC <bc@freeuk.com> - 2016-03-11 01:45 +0000
Re: Simple exercise Larry Martell <larry.martell@gmail.com> - 2016-03-10 20:53 -0500
Re: Simple exercise "Martin A. Brown" <martin@linux-ip.net> - 2016-03-10 17:56 -0800
Re: Simple exercise Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-11 02:03 +0000
Re: Simple exercise BartC <bc@freeuk.com> - 2016-03-11 02:18 +0000
Re: Simple exercise Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-14 07:35 -0700
Re: Simple exercise Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-03-14 15:06 +0000
Re: Simple exercise Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-14 09:00 -0700
Re: Simple exercise Steven D'Aprano <steve@pearwood.info> - 2016-03-15 10:59 +1100
Re: Simple exercise Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-15 07:26 +0200
Re: Simple exercise Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-03-15 19:39 +1100
Re: Simple exercise Chris Angelico <rosuav@gmail.com> - 2016-03-15 19:53 +1100
Re: Simple exercise Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-03-15 11:04 +0200
Re: Simple exercise Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2016-03-15 11:09 +0000
Re: Simple exercise Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-14 09:16 -0600
Re: Simple exercise Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-14 09:11 -0700
Re: Simple exercise Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-14 15:23 +0000
Re: Simple exercise Peter Otten <__peter__@web.de> - 2016-03-14 17:00 +0100
Re: Simple exercise Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-11 02:05 +0000
Re: Simple exercise Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-14 07:07 -0700
Re: Simple exercise Larry Martell <larry.martell@gmail.com> - 2016-03-14 10:13 -0400
Re: Simple exercise alister <alister.ware@ntlworld.com> - 2016-03-14 14:18 +0000
Re: Simple exercise Rick Johnson <rantingrickjohnson@gmail.com> - 2016-03-14 08:22 -0700
Re: Simple exercise MRAB <python@mrabarnett.plus.com> - 2016-03-14 15:57 +0000
Re: Simple exercise Chris Kaynor <ckaynor@zindagigames.com> - 2016-03-10 18:14 -0800
Re: Simple exercise boffi <boffi@casa.sua> - 2016-03-17 22:28 +0100
csiph-web