Re: Idiomatic Python for incrementing pairs

2013-06-08 Thread Steven D'Aprano
On Fri, 07 Jun 2013 21:32:39 -0500, Tim Chase wrote: 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 [...skip misleading and irrelevant calculate() function...] alpha = beta = 0

Re: Idiomatic Python for incrementing pairs

2013-06-08 Thread Peter Otten
Tim Chase wrote: On 2013-06-07 23:46, Jason Swails wrote: On Fri, Jun 7, 2013 at 10:32 PM, Tim Chase def calculate(params): a = b = 0 if some_calculation(params): a += 1 if other_calculation(params): b += 1 return (a, b) alpha = beta = 0

Re: Idiomatic Python for incrementing pairs

2013-06-08 Thread Jason Swails
On Sat, Jun 8, 2013 at 2:47 AM, Peter Otten __pete...@web.de wrote: You can hide the complexity in a custom class: class T(tuple): ... def __add__(self, other): ... return T((a+b) for a, b in zip(self, other)) ... t = T((0, 0)) for pair in [(1, 10), (2, 20), (3, 30)]:

Re: Idiomatic Python for incrementing pairs

2013-06-08 Thread Terry Jan Reedy
On 6/8/2013 12:16 AM, Tim Chase wrote: 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

Idiomatic Python for incrementing pairs

2013-06-07 Thread Tim Chase
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,

Re: Idiomatic Python for incrementing pairs

2013-06-07 Thread Jason Swails
On Fri, Jun 7, 2013 at 10:32 PM, Tim Chase python.l...@tim.thechases.comwrote: 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

Re: Idiomatic Python for incrementing pairs

2013-06-07 Thread Chris Angelico
On Sat, Jun 8, 2013 at 12:32 PM, Tim Chase python.l...@tim.thechases.com wrote: 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(...)

RE: Idiomatic Python for incrementing pairs

2013-06-07 Thread Carlos Nepomuceno
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.l...@tim.thechases.com To: python-list@python.org Subject: Idiomatic Python for incrementing pairs Playing around, I've been trying to figure out

Re: Idiomatic Python for incrementing pairs

2013-06-07 Thread Tim Chase
On 2013-06-07 23:46, Jason Swails wrote: On Fri, Jun 7, 2013 at 10:32 PM, Tim Chase 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 =

Re: Idiomatic Python for incrementing pairs

2013-06-07 Thread Tim Chase
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

RE: Idiomatic Python for incrementing pairs

2013-06-07 Thread Carlos Nepomuceno
:22 -0500 From: python.l...@tim.thechases.com To: carlosnepomuc...@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