Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #47365
| Date | 2013-06-07 23:16 -0500 |
|---|---|
| From | Tim Chase <python.list@tim.thechases.com> |
| Subject | Re: Idiomatic Python for incrementing pairs |
| References | <20130607213239.3e39a448@bigbox.christie.dr> <BLU176-W41787828AF1636314057B8D79A0@phx.gbl> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2875.1370664872.3114.python-list@python.org> (permalink) |
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 question does the initialization outside a loop:
alphas_updated = betas_updated = 0
for thing in bunch_of_things:
a, b = process(thing)
alphas_updated += a
betas_updated += b
and it just bugs me as being a little warty for having temp
variables when Python does things like tuple-unpacking so elegantly.
That said, as mentioned in a contemporaneous reply to Jason, I haven't
found anything better that is still readable.
-tkc
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Idiomatic Python for incrementing pairs Tim Chase <python.list@tim.thechases.com> - 2013-06-07 23:16 -0500
csiph-web