Verbose and flexible args and kwargs syntax

Terry Reedy tjreedy at udel.edu
Mon Dec 12 03:44:51 EST 2011


On 12/11/2011 6:44 PM, Eelco Hoogendoorn wrote:

> Can you come up with some terse symbols that will be able to express all
> of the below and dont make you wish you hadnt rather typed out the names?
>
> head, tuple(tail) = iterable
> head, list(tail) = iterable
> head, str(tail) = somestring
> head, generator(tail) = mygenerator

The above examples are seldom needed in Python because we have one 
general method to repeatedly split a sequence into head and tail.

it = iter(iterable) # 'it' now represents the sequenced iterable
head = next(it) # 'it' now represents the tail after removing the head

In other words, next(it) encompasses all of your examples and many more.
Because 'it' is mutated to represent the tail, it does not need to be 
rebound and therefore is not.

Iterable unpacking with a *target for leftovers is an entirely different 
use case.

-- 
Terry Jan Reedy




More information about the Python-list mailing list