[Python-Dev] Half-baked proposal: * (and **?) in assignments
Sun, 24 Nov 2002 10:57:44 +1100
> From: Gareth McCaughan [mailto:Gareth.McCaughan@pobox.com]
> a,b,*c = 1,2,3,4,5
FWIW, this has been proposed before, but no one ever bothered to make a PEP
Each time it's come up, my gut feeling has been that I would really like it.
I've often been in the situation where I'd *like* to pass a variable-length
tuple from a function, but the current way of splitting it up is too clunky.
I hadn't thought of it before, but I do like the suggestion of allowing * in
any location of the LHS. This would of course require that the LHS contains
exactly zero or one * i.e.
a, b, c = t
*a, b, c = t # all leading into a, 2nd-last into b, last into c
a, *b, c = t # first into a, all middle into b, last into c
a, b, *c = t # first into a, second into b, all trailing into c
would all be legal constructs, but
*a, *b, c = t
a, *b, *c = t
*a, b, *c = t
*a, *b, *c = t
would all be illegal constructs.
I think the addition of this would lead to a more functional style of
programming. This may be a plus for some people, and a minus for others.
For myself, the idea (including arbitrary placement of the *) is +1.
However, I'm -1 on the idea of additional syntax on the RHS.