RE: [Python-Dev] Tuple/list assignment question

Dave Cole wrote:
Is there any reason why something like this would not be a good idea?
a_list = [1, 2, 3, 4, 5] a, b, *c = a_list
You could then do things like this:
lol = [[1, 2], [3, 4, 5, 6, 7], [8, 9, 10, 11, 12, 13]] for a, b *c in lol: ...
This proposal has come up several times before (for the record, I like it). I believe there was a particular reason it's never gone forward, but I can't remember what it was. Unfortunately, it's not an easy thing to search for in the c.l.py archives :( I think it's about time this proposal got a PEP of its own ... something like "Enhanced Tuple Unpacking" (to match "Enhanced Argument Tuples" ... Tim Delaney

This proposal has come up several times before (for the record, I like it).
The fact that it keeps coming up suggests that it's a natural thing for people to want to do once they've seen the use of * in argument lists. I can't remember seeing any particular objection -- just a matter of inertia, I think (i.e. nice to have but not compelling enough to spur the BDFL to accept it). Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg@cosc.canterbury.ac.nz +--------------------------------------+

Greg Ewing wrote:
I can't remember seeing any particular objection -- just a matter of inertia, I think (i.e. nice to have but not compelling enough to spur the BDFL to accept it).
This certainly summarises my reason for criticising it. It's application to a basic 'command parsing' scenario was a useful case I hadn't thought of, though:
commands = line.split() for line in commandFile.readlines() for command, *args in commands do: func_table[command](*args)
However, the slicing based alternative is fairly readable, too and if the BDFL says the interpreter changes needed to support the feature are too drastic, I'm willing to believe him :) Regards, Nick. -- Nick Coghlan | Eugene, Oregon Email: ncoghlan@email.com | USA

Delaney, Timothy C (Timothy <tdelaney <at> avaya.com> writes:
I think it's about time this proposal got a PEP of its own ... something like "Enhanced Tuple Unpacking" (to match "Enhanced Argument Tuples" ...
Even the PEP would be rejected, I think it's a good idea to have the definitive answer of the BDFL. Maxime
participants (4)
-
Delaney, Timothy C (Timothy)
-
Greg Ewing
-
maxime B
-
Nick Coghlan