[Python-ideas] list / array comprehensions extension
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
>>> 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
>>> 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.
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
> Python-ideas mailing list
> Python-ideas at python.org
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...
More information about the Python-ideas