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


Groups > comp.lang.python > #47363

RE: Idiomatic Python for incrementing pairs

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <carlosnepomuceno@outlook.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.035
X-Spam-Evidence '*H*': 0.93; '*S*': 0.00; 'subject:Python': 0.06; '-0500': 0.09; 'python': 0.11; 'def': 0.12; '-tkc': 0.16; 'alpha,': 0.16; 'pairs': 0.16; 'pythonic': 0.16; 'alpha': 0.16; 'trying': 0.19; 'to:name:python-list@python.org': 0.22; 'received:65.55.116': 0.24; "i've": 0.25; '&gt;': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'url:mailman': 0.30; 'figure': 0.32; 'url:python': 0.33; 'fri,': 0.33; 'date:': 0.34; 'something': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'email addr:python.org': 0.37; 'skip:o 20': 0.38; 'to:addr :python-list': 0.38; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'most': 0.60; 'email name:python-list': 0.65; 'holding': 0.65; 'temporary': 0.65; 'around,': 0.84; '2013': 0.98
X-TMN [88QxWnv5ECpG0KGKgj52zk8l0IEucSkP]
X-Originating-Email [carlosnepomuceno@outlook.com]
Content-Type multipart/alternative; boundary="_29d5b315-b00d-41fb-a293-16fdc3365797_"
From Carlos Nepomuceno <carlosnepomuceno@outlook.com>
To "python-list@python.org" <python-list@python.org>
Subject RE: Idiomatic Python for incrementing pairs
Date Sat, 8 Jun 2013 07:04:21 +0300
Importance Normal
In-Reply-To <20130607213239.3e39a448@bigbox.christie.dr>
References <20130607213239.3e39a448@bigbox.christie.dr>
MIME-Version 1.0
X-OriginalArrivalTime 08 Jun 2013 04:04:21.0586 (UTC) FILETIME=[416CFB20:01CE63FD]
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2873.1370664271.3114.python-list@python.org> (permalink)
Lines 77
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1370664271 news.xs4all.nl 15912 [2001:888:2000:d::a6]:56607
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:47363

Show key headers only | 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