Idiomatic Python for incrementing pairs
Carlos Nepomuceno
carlosnepomuceno at outlook.com
Sat Jun 8 00:04:21 EDT 2013
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 at tim.thechases.com
> To: python-list at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130608/6fc9adb1/attachment.html>
More information about the Python-list
mailing list