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


Groups > comp.lang.python > #43635

Re: Process tuple contents on the fly

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!us.feeder.erje.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder5.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python.list@tim.thechases.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'assignment': 0.07; 'append': 0.09; 'assigning': 0.09; 'cc:addr:python-list': 0.11; '"for"': 0.16; '-tkc': 0.16; '[*]': 0.16; 'd[key]': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'loop.': 0.16; 'possible?': 0.16; 'stumbled': 0.16; 'tup': 0.16; 'tuple': 0.16; 'variables:': 0.16; 'applies': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'cc:addr:python.org': 0.22; 'print': 0.22; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'least': 0.26; 'header:In-Reply- To:1': 0.27; 'statement': 0.30; 'discovery': 0.31; 'quite': 0.32; 'plain': 0.33; 'subject:the': 0.34; 'could': 0.34; 'but': 0.35; 'var': 0.36; 'charset:us-ascii': 0.36; 'list': 0.37; 'step': 0.37; 'to:addr:gmail.com': 0.65; 'received:50.22': 0.84; 'step,': 0.84
Date Mon, 15 Apr 2013 13:50:13 -0500
From Tim Chase <python.list@tim.thechases.com>
To Gnarlodious <gnarlodious@gmail.com>
Subject Re: Process tuple contents on the fly
In-Reply-To <f51058c3-0e36-429c-85d9-365be82b548f@googlegroups.com>
References <f51058c3-0e36-429c-85d9-365be82b548f@googlegroups.com>
X-Mailer Claws Mail 3.7.6 (GTK+ 2.20.1; x86_64-pc-linux-gnu)
Mime-Version 1.0
Content-Type text/plain; charset=US-ASCII
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - boston.accountservergroup.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - tim.thechases.com
Cc python-list@python.org
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.640.1366051720.3114.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1366051720 news.xs4all.nl 2676 [2001:888:2000:d::a6]:47175
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43635

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