Verbose and flexible args and kwargs syntax
Terry Reedy
tjreedy at udel.edu
Mon Dec 12 10:52:25 EST 2011
On 12/12/2011 4:12 AM, Eelco Hoogendoorn wrote:
>> 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.
>
>
> The question in language design is never 'could we do these things
> before'. The answer is obvious: yes our CPUs are turing complete; we can
> do anything. The question is; how would we like to do them?
>
> So do you think the new head/tail unpacking features in python 3 are
> entirely uncalled for?
No, *target unpacking (singular) is quite useful in specialized cases.
But it is not specifically head/tail unpacking.
>>> a,*b,c = 1,2,3,4,5,6
>>> a,b,c
(1, [2, 3, 4, 5], 6)
>>> *a,b,c = 1,2,3,4,5
>>> a,b,c
([1, 2, 3], 4, 5)
> I personally quite like them, but I would like them to be more general.
It already is. The *target can be anywhere in the sequence.
--
Terry Jan Reedy
More information about the Python-list
mailing list