Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #47366
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <carlosnepomuceno@outlook.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.06; 'variables': 0.07; '-0500': 0.09; 'variables.': 0.09; 'python': 0.11; '(alpha': 0.16; '-tkc': 0.16; '0))': 0.16; '0),': 0.16; 'alpha,': 0.16; 'instead:': 0.16; 'pairs': 0.16; 'temp': 0.16; 'alpha': 0.16; 'wrote:': 0.18; 'to:name:python-list@python.org': 0.22; 'received:65.55.116': 0.24; "haven't": 0.24; 'question': 0.24; '>': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'absolute': 0.30; 'said,': 0.30; 'sets': 0.30; 'code': 0.31; 'question:': 0.31; 'bugs': 0.33; 'fri,': 0.33; 'actual': 0.34; 'date:': 0.34; 'really': 0.36; 'doing': 0.36; 'next': 0.36; 'email addr:python.org': 0.37; 'being': 0.38; 'skip:o 20': 0.38; 'to:addr :python-list': 0.38; 'rather': 0.38; 'little': 0.38; 'anything': 0.39; 'does': 0.39; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'mentioned': 0.61; 're:': 0.63; 'email name:python-list': 0.65; 'reply': 0.66; 'carlos': 0.91; '2013': 0.98 |
| X-TMN | [lTgMu9V0NGMsuJL9sKncZL2iGlt/IlMd] |
| X-Originating-Email | [carlosnepomuceno@outlook.com] |
| Content-Type | multipart/alternative; boundary="_bd74b720-51f6-4880-88d6-064456a2eae2_" |
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
| To | "python-list@python.org" <python-list@python.org> |
| Subject | RE: Idiomatic Python for incrementing pairs |
| Date | Sat, 8 Jun 2013 07:16:58 +0300 |
| Importance | Normal |
| In-Reply-To | <20130607231622.31cb120b@bigbox.christie.dr> |
| References | <20130607231622.31cb120b@bigbox.christie.dr> |
| MIME-Version | 1.0 |
| X-OriginalArrivalTime | 08 Jun 2013 04:16:58.0634 (UTC) FILETIME=[04A956A0:01CE63FF] |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2876.1370665087.3114.python-list@python.org> (permalink) |
| Lines | 92 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1370665087 news.xs4all.nl 15943 [2001:888:2000:d::a6]:36763 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:47366 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Oh! I really though you were just adding 1 or 0 to those variables. In clude the loop next time! ;) You can accumulate the values by doing this instead: alpha, beta = (alpha + (1 if some_calculation(params) else 0), beta + (1 if other_calculation(params) else 0)) > Date: Fri, 7 Jun 2013 23:16:22 -0500 > From: python.list@tim.thechases.com > To: carlosnepomuceno@outlook.com > CC: python-list@python.org > Subject: Re: Idiomatic Python for incrementing pairs > > On 2013-06-08 07:04, Carlos Nepomuceno wrote: > > alpha, beta = (1 if some_calculation(params) else 0, 1 if > > other_calculation(params) else 0) > > This one sets them to absolute values, rather than the incrementing > functionality in question: > > > > alpha += temp_a > > > beta += temp_b > > The actual code in question does the initialization outside a loop: > > alphas_updated = betas_updated = 0 > for thing in bunch_of_things: > a, b = process(thing) > alphas_updated += a > betas_updated += b > > and it just bugs me as being a little warty for having temp > variables when Python does things like tuple-unpacking so elegantly. > That said, as mentioned in a contemporaneous reply to Jason, I haven't > found anything better that is still readable. > > -tkc > > >
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
RE: Idiomatic Python for incrementing pairs Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-08 07:16 +0300
csiph-web