Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #47363 > unrolled thread
| Started by | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| First post | 2013-06-08 07:04 +0300 |
| Last post | 2013-06-08 07:04 +0300 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
RE: Idiomatic Python for incrementing pairs Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-06-08 07:04 +0300
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Date | 2013-06-08 07:04 +0300 |
| Subject | RE: Idiomatic Python for incrementing pairs |
| Message-ID | <mailman.2873.1370664271.3114.python-list@python.org> |
[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 top | Article view | comp.lang.python
csiph-web