Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'append': 0.09; 'assigning': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.12; "'b',": 0.16; "'c',": 0.16; "['a',": 0.16; 'possible?': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'side.': 0.16; 'stumbled': 0.16; 'tup': 0.16; 'tuple': 0.16; 'variables:': 0.16; ':-)': 0.16; 'wrote:': 0.18; 'variable': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'least': 0.26; 'header:X -Complaints-To:1': 0.27; 'tim': 0.29; 'chase': 0.31; 'quite': 0.32; 'subject:the': 0.34; 'could': 0.34; 'but': 0.35; 'var': 0.36; 'wrong': 0.37; 'list': 0.37; 'step': 0.37; 'star': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'skip:* 10': 0.61; 'step,': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: Process tuple contents on the fly Date: Mon, 15 Apr 2013 21:07:32 +0200 Organization: None References: <20130415135013.58430065@bigbox.christie.dr> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084aa7b.dip.t-dialin.net User-Agent: KNode/4.7.3 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: 1366052854 news.xs4all.nl 2670 [2001:888:2000:d::a6]:53690 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43638 Tim Chase wrote: > 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 :-) I think the star is on the wrong side. So: >>> items = ["a", "b", "c"] >>> def f(result=(4, 5, 6)): return result ... >>> var, *items[len(items):] = f() >>> var 4 >>> items ['a', 'b', 'c', 5, 6]