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


Groups > comp.lang.python > #47366 > unrolled thread

RE: Idiomatic Python for incrementing pairs

Started byCarlos Nepomuceno <carlosnepomuceno@outlook.com>
First post2013-06-08 07:16 +0300
Last post2013-06-08 07:16 +0300
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  RE: Idiomatic Python for incrementing pairs Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-08 07:16 +0300

#47366 — RE: Idiomatic Python for incrementing pairs

FromCarlos Nepomuceno <carlosnepomuceno@outlook.com>
Date2013-06-08 07:16 +0300
SubjectRE: Idiomatic Python for incrementing pairs
Message-ID<mailman.2876.1370665087.3114.python-list@python.org>

[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
> 
> 
> 
 		 	   		  

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web