[Python-3000] PEP 3132: Extended Iterable Unpacking

Chris Rebert cvrebert at gmail.com
Wed May 2 03:51:24 CEST 2007


In the interest of furthering the discussion, here are two past
threads on similar suggestions:

[Python-Dev] Half-baked proposal: * (and **?) in assignments
http://mail.python.org/pipermail/python-dev/2002-November/030349.html

[Python-ideas] Javascript Destructuring Assignment
http://mail.python.org/pipermail/python-ideas/2007-March/000284.html

- Chris Rebert

On 5/1/07, Christian Heimes <lists at cheimes.de> wrote:
> Neville Grech Neville Grech wrote:
> > This reminds me a lot of haskell/prolog's head/tail list splitting. Looks
> > like a good feature.
>
> Agreed!
> > a*=range(5)
> > hmmn maybe in such a case, whenever there is the * operator, the resulting
> > item is always a list/tuple, like the following:
> > a=[[0,1,2,3,4]] ?
>
> Did you mean *a = range(5)?
> The result is too surprising for me. I would suspect that *a = range(5)
> has the same output as a = range(5).
>
>  >>> *b = (1, 2, 3)
>  >>> b
> (1, 2, 3)
>
>  >>> a, *b = (1, 2, 3)
>  >>> a, b
> 1, (2, 3)
>
>  >>> *b, c = (1, 2, 3)
>  >>> b, c
> (1, 2), 3
>
>
>  >>> a, *b, c = (1, 2, 3)
>  >>> a, b, c
> 1, (2,), 3
>
> But what would happen when the right side is too small?
>  >>> a, *b, c = (1, 2)
>  >>> a, b, c
> 1, (), 2
>
> or should it raise an unpack exception?
>
> This should definitely raise an exception
>  >>> a, *b, c, d = (1, 2)
>
> Christian
>
> _______________________________________________
> Python-3000 mailing list
> Python-3000 at python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/cvrebert%40gmail.com
>


More information about the Python-3000 mailing list