[Python-3000] PEP 3132: Extended Iterable Unpacking
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
- 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.
> > 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)
> Python-3000 mailing list
> Python-3000 at python.org
> Unsubscribe: http://mail.python.org/mailman/options/python-3000/cvrebert%40gmail.com
More information about the Python-3000