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: 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 To: "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: <20130607213239.3e39a448@bigbox.christie.dr>, , <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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 --_bd74b720-51f6-4880-88d6-064456a2eae2_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Oh! I really though you were just adding 1 or 0 to those variables. In clud= e the loop next time! =3B) You can accumulate the values by doing this instead: alpha=2C beta =3D (alpha + (1 if some_calculation(params) else 0)=2C beta += (1 if other_calculation(params) else 0)) > Date: Fri=2C 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 >=20 > On 2013-06-08 07:04=2C Carlos Nepomuceno wrote: > > alpha=2C beta =3D (1 if some_calculation(params) else 0=2C 1 if > > other_calculation(params) else 0) >=20 > This one sets them to absolute values=2C rather than the incrementing > functionality in question: >=20 > > > alpha +=3D temp_a > > > beta +=3D temp_b >=20 > The actual code in question does the initialization outside a loop: >=20 > alphas_updated =3D betas_updated =3D 0 > for thing in bunch_of_things: > a=2C b =3D process(thing) > alphas_updated +=3D a > betas_updated +=3D b >=20 > 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=2C as mentioned in a contemporaneous reply to Jason=2C I haven'= t > found anything better that is still readable. >=20 > -tkc >=20 >=20 >=20 = --_bd74b720-51f6-4880-88d6-064456a2eae2_ Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
Oh! I really though you were jus= t adding 1 or 0 to those variables. In clude the loop next time! =3B)
You can accumulate the values by doing this instead:

alpha=2C beta= =3D (alpha + (1 if some_calculation(params) else 0)=2C beta + (1 if other_= calculation(params) else 0))

>=3B Date: Fri=2C 7 Jun 2013 23:= 16:22 -0500
>=3B From: python.list@tim.thechases.com
>=3B To: car= losnepomuceno@outlook.com
>=3B CC: python-list@python.org
>=3B Su= bject: Re: Idiomatic Python for incrementing pairs
>=3B
>=3B On = 2013-06-08 07:04=2C Carlos Nepomuceno wrote:
>=3B >=3B alpha=2C beta= =3D (1 if some_calculation(params) else 0=2C 1 if
>=3B >=3B other_c= alculation(params) else 0)
>=3B
>=3B This one sets them to absol= ute values=2C rather than the incrementing
>=3B functionality in quest= ion:
>=3B
>=3B >=3B >=3B alpha +=3D temp_a
>=3B >= =3B >=3B beta +=3D temp_b
>=3B
>=3B The actual code in quest= ion does the initialization outside a loop:
>=3B
>=3B alphas_u= pdated =3D betas_updated =3D 0
>=3B for thing in bunch_of_things:>=3B a=2C b =3D process(thing)
>=3B alphas_updated +=3D a>=3B betas_updated +=3D b
>=3B
>=3B and it just bugs me = as being a little warty for having temp
>=3B variables when Python doe= s things like tuple-unpacking so elegantly.
>=3B That said=2C as menti= oned in a contemporaneous reply to Jason=2C I haven't
>=3B found anyth= ing better that is still readable.
>=3B
>=3B -tkc
>=3B
= >=3B
>=3B
= --_bd74b720-51f6-4880-88d6-064456a2eae2_--