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: 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 To: Gnarlodious Subject: Re: Process tuple contents on the fly In-Reply-To: References: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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.