Style question on recursive generators

Dima Dorfman null at trit.org
Tue Oct 19 08:49:21 EDT 2004


Alex Martelli wrote:
> Dima Dorfman wrote:
> >   yield *other
> 
> say:
>     a = b, *c, d
> meaning the same as
>     a = (b,) + tuple(c) + (d,)
> or the old, currently out of favour proposal
>     a, b, c, *d = e

Both of these are intuitive to me. I'm generally in favor of expanding
the use of '*' to mean aggregation in this manner, but someone else is
gonna have to organize the crusade if they want one.

> where d gets (an iterator for) 'the rest of e' after the first three
> items of e are unpacked to a, b, and c.

FWIW, the implementation for the unpacking case is mostly straight-
forward (I did one a while back). The only caveat is what to do with
*d. You suggest storing an iterator for the rest of e, but this is
unuseful if e is a real sequence, like a tuple. It's easy enough to
special-case tuples and lists, but what about other user-defined
types? Maybe slice off the rest? Real iterators (iter(x) is x) would
have to be treated specially in any case.



More information about the Python-list mailing list