[Python-ideas] list / array comprehensions extension

Michael Foord fuzzyman at gmail.com
Thu Dec 15 19:02:24 CET 2011

On 15 December 2011 17:53, Steven D'Aprano <steve at pearwood.info> wrote:

> Michael Foord wrote:
>> On 15 December 2011 17:35, Alexander Heger <python at 2sn.net> wrote:
>>  Dear Masklinn,
>>> thanks for your suggested solution.
>>> I know all of these, but
>>> 1) it is not as elegant or short
>>> 2) why does unpacking not work syntactically the same as for the function
>>> parameters?
>>> It seems a natural extension that appears not to have a syntactic
>>> conflict.  If it is not even a necessity for consistency.
>>> So, the point is not that something like
>>> [0,*x,0,*y,0]
>>> can't be done in other ways, but that it can't be done in a neat way.
>> I quite like that (suggested) syntax.
> So do I. But I question the need for it.
> +0.
Well, the new tuple unpacking syntax makes it easy to work with the head
and tail of a sequence:

    head, *rest = some_sequence
   *rest, tail = some_sequence

This syntax provides a corollary:

    some_sequence = (head, *rest)
    some_sequence = (*rest, tail)

Tuple unpacking like this being the equivalent of car and cdr, with the
corollary being the equivalent of cons. (Given my limited understanding of
these operations.)


> --
> Steven
> ______________________________**_________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/**mailman/listinfo/python-ideas<http://mail.python.org/mailman/listinfo/python-ideas>



May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20111215/82c0633c/attachment.html>

More information about the Python-ideas mailing list