Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17023

Re: Verbose and flexible args and kwargs syntax

From Terry Reedy <tjreedy@udel.edu>
Subject Re: Verbose and flexible args and kwargs syntax
Date 2011-12-12 03:44 -0500
References <4EE54066.3020901@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.3534.1323679511.27778.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Verbose and flexible args and kwargs syntax Terry Reedy <tjreedy@udel.edu> - 2011-12-12 03:44 -0500

csiph-web