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


Groups > comp.lang.python > #47358

Idiomatic Python for incrementing pairs

Date 2013-06-07 21:32 -0500
From Tim Chase <python.list@tim.thechases.com>
Subject Idiomatic Python for incrementing pairs
Newsgroups comp.lang.python
Message-ID <mailman.2868.1370658654.3114.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Idiomatic Python for incrementing pairs Tim Chase <python.list@tim.thechases.com> - 2013-06-07 21:32 -0500
  Re: Idiomatic Python for incrementing pairs Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-06-08 06:39 +0000

csiph-web