* for generic unpacking and not just for arguments?

Russell Warren russandheather at gmail.com
Sun Nov 29 13:01:42 EST 2009


On Nov 29, 11:09 am, Christian Heimes <li... at cheimes.de> wrote:
> The feature is available in Python 3.x:
>
> >>> a, b, *c = 1, 2, 3, 4, 5
> >>> a, b, c
> (1, 2, [3, 4, 5])
> >>> a, *b, c = 1, 2, 3, 4, 5
> >>> a, b, c
>
> (1, [2, 3, 4], 5)

Interesting... especially the recognition of how both ends work with
the "a, *b, c" example.  That is some funky syntax.  And it goes to a
list instead of a tuple now, I see.

It is also the opposite of what I was considering, although I expect
it goes both ways like it does for functions?  The given python 3.0
example is on the LHS with * packing many-to-one while unpacking (like
*args inside a function), whereas I was referring to RHS-style
unpacking where * explodes/unpacks one-to-many (like passing *args
_to_ a function).

I've steered clear of 3.x so far, but it looks like I'll have to give
it a whirl if only to avoid asking irrelevant questions!



More information about the Python-list mailing list