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


Groups > comp.lang.python > #43635

Re: Process tuple contents on the fly

Date 2013-04-15 13:50 -0500
From Tim Chase <python.list@tim.thechases.com>
Subject Re: Process tuple contents on the fly
References <f51058c3-0e36-429c-85d9-365be82b548f@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.640.1366051720.3114.python-list@python.org> (permalink)

Show all headers | View raw


On 2013-04-15 11:25, Gnarlodious wrote:
> Say I have a tuple I want to expand assigning to variables:
> 
> tup = *func()
> var = tup[0]
> lst.append(tup[1])
> 
> Or could I do it in one line?
> 
> var, lst.append() = *func()
> 
> So I want to append one variable to a list on the fly, is it
> possible?

I stumbled across this atrocity[*], which if you chose to use it,
you'd deserve a kick in the pants:

  lst.append("Value I don't care about and will overwrite")
  var, lst[-1] = *func()

It's not quite one step, but at least the *assignment* is one step :-)

-tkc


[*] my original discovery was

  d = {}
  for key, d[key] in (("this",18), ("that",17), ("other",38)):
    print key
    do_something(d)

but the same applies to a plain ol' assignment statement as to an
assignment in a "for" loop.




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


Thread

Process tuple contents on the fly Gnarlodious <gnarlodious@gmail.com> - 2013-04-15 11:25 -0700
  Re: Process tuple contents on the fly Tim Chase <python.list@tim.thechases.com> - 2013-04-15 13:50 -0500
  Re: Process tuple contents on the fly Barrett Lewis <musikal.fusion@gmail.com> - 2013-04-15 12:05 -0700
  Re: Process tuple contents on the fly Peter Otten <__peter__@web.de> - 2013-04-15 21:07 +0200
  Re: Process tuple contents on the fly Tim Chase <python.list@tim.thechases.com> - 2013-04-15 14:10 -0500
  Re: Process tuple contents on the fly Barrett Lewis <musikal.fusion@gmail.com> - 2013-04-15 12:16 -0700
  Re: Process tuple contents on the fly MRAB <python@mrabarnett.plus.com> - 2013-04-15 20:29 +0100
  Re: Process tuple contents on the fly Tobiah <toby@tobiah.org> - 2013-04-15 13:35 -0700
    Re: Process tuple contents on the fly Michael Torrie <torriem@gmail.com> - 2013-04-15 15:16 -0600
    Re: Process tuple contents on the fly Gnarlodious <gnarlodious@gmail.com> - 2013-04-15 16:46 -0700

csiph-web