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


Groups > comp.lang.python > #47365

Re: Idiomatic Python for incrementing pairs

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.011
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'subject:Python': 0.06; 'variables': 0.07; 'cc:addr:python-list': 0.11; 'python': 0.11; '-tkc': 0.16; 'alpha,': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'temp': 0.16; 'alpha': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; "haven't": 0.24; 'question': 0.24; 'cc:2**0': 0.24; '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; 'actual': 0.34; 'charset:us-ascii': 0.36; 'being': 0.38; 'skip:o 20': 0.38; 'rather': 0.38; 'little': 0.38; 'anything': 0.39; 'does': 0.39; 'mentioned': 0.61; 'reply': 0.66; 'received:50.22': 0.84; 'carlos': 0.91
Date Fri, 7 Jun 2013 23:16:22 -0500
From Tim Chase <python.list@tim.thechases.com>
To Carlos Nepomuceno <carlosnepomuceno@outlook.com>
Subject Re: Idiomatic Python for incrementing pairs
In-Reply-To <BLU176-W41787828AF1636314057B8D79A0@phx.gbl>
References <20130607213239.3e39a448@bigbox.christie.dr> <BLU176-W41787828AF1636314057B8D79A0@phx.gbl>
X-Mailer Claws Mail 3.7.6 (GTK+ 2.20.1; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
Cc "python-list@python.org" <python-list@python.org>
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.2875.1370664872.3114.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1370664872 news.xs4all.nl 15964 [2001:888:2000:d::a6]:34381
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:47365

Show key headers only | View raw


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


Thread

Re: Idiomatic Python for incrementing pairs Tim Chase <python.list@tim.thechases.com> - 2013-06-07 23:16 -0500

csiph-web