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
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
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)]:
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
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,
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
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(...)
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
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 =
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
: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
11 matches
Mail list logo