[Python-3000] PEP 3132: Extended Iterable Unpacking (original) (raw)
Brett Cannon brett at python.org
Wed May 2 04:02:11 CEST 2007
- Previous message: [Python-3000] PEP 3132: Extended Iterable Unpacking
- Next message: [Python-3000] PEP 3132: Extended Iterable Unpacking
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 5/1/07, Guido van Rossum <guido at python.org> wrote:
On 5/1/07, Georg Brandl <g.brandl at gmx.net> wrote: > This is a bit late, but it was in my queue by April 30, I swear! ;) Accepted. > Comments are appreciated, especially some phrasing sounds very clumsy > to me, but I couldn't find a better one. > > Georg > > > PEP: 3132 > Title: Extended Iterable Unpacking > Version: RevisionRevisionRevision > Last-Modified: DateDateDate > Author: Georg Brandl <georg at python.org> > Status: Draft > Type: Standards Track > Content-Type: text/x-rst > Created: 30-Apr-2007 > Python-Version: 3.0 > Post-History: > > > Abstract > ======== > > This PEP proposes a change to iterable unpacking syntax, allowing to > specify a "catch-all" name which will be assigned a list of all items > not assigned to a "regular" name. > > An example says more than a thousand words:: > > >>> a, *b, c = range(5) > >>> a > 0 > >>> c > 4 > >>> b > [1, 2, 3] Has it been pointed out to you already that this particular example is hard to implement if the RHS is an iterator whose length is not known a priori? The implementation would have to be quite hairy -- it would have to assign everything to the list b until the iterator is exhausted, and then pop a value from the end of the list and assign it to c. it would be much easier if *b was only allowed at the end. (It would be even worse if b were assigned a tuple instead of a list, as per your open issues.)
If a clean implementation solution cannot be found then I say go with the last-item-only restriction. You still get the nice functional language feature of car/cdr (or x:xs if you prefer ML or Haskell) without the implementation headache. I mean how often do you want the head and tail with everything in between left together? If I needed that kind of sequence control I would feed the iterator to a list comp and get to the items that way.
Also, what should this do? Perhaps the grammar could disallow it?
*a = range(5)
I say disallow it. That is ambiguous as to what your intentions are even if you know what '*' does for multiple assignment.
-Brett -------------- next part -------------- An HTML attachment was scrubbed... URL: http://mail.python.org/pipermail/python-3000/attachments/20070501/6af84286/attachment.htm
- Previous message: [Python-3000] PEP 3132: Extended Iterable Unpacking
- Next message: [Python-3000] PEP 3132: Extended Iterable Unpacking
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]