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


Groups > comp.lang.python > #47363

RE: Idiomatic Python for incrementing pairs

From Carlos Nepomuceno <carlosnepomuceno@outlook.com>
Subject RE: Idiomatic Python for incrementing pairs
Date 2013-06-08 07:04 +0300
References <20130607213239.3e39a448@bigbox.christie.dr>
Newsgroups comp.lang.python
Message-ID <mailman.2873.1370664271.3114.python-list@python.org> (permalink)

Show all headers | View raw


[Multipart message — attachments visible in raw view] - view raw

alpha, beta = (1 if some_calculation(params) else 0, 1 if other_calculation(params) else 0)

> Date: Fri, 7 Jun 2013 21:32:39 -0500
> From: python.list@tim.thechases.com
> To: python-list@python.org
> Subject: Idiomatic Python for incrementing pairs
> 
> Playing around, I've been trying to figure out the most pythonic way
> of incrementing multiple values based on the return of a function.
> Something like
> 
>   def calculate(params):
>     a = b = 0
>     if some_calculation(params):
>       a += 1
>     if other_calculation(params):
>       b += 1
>     return (a, b)
> 
>   alpha = beta = 0
>   temp_a, temp_b = calculate(...)
>   alpha += temp_a
>   beta += temp_b
> 
> Is there a better way to do this without holding each temporary
> result before using it to increment?
> 
> -tkc
> 
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
 		 	   		  

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web