Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43638
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Subject | Re: Process tuple contents on the fly |
| Date | 2013-04-15 21:07 +0200 |
| Organization | None |
| References | <f51058c3-0e36-429c-85d9-365be82b548f@googlegroups.com> <20130415135013.58430065@bigbox.christie.dr> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.642.1366052854.3114.python-list@python.org> (permalink) |
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]
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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