[Python-ideas] list / array comprehensions extension
Masklinn
masklinn at masklinn.net
Thu Dec 15 19:28:51 CET 2011
On 2011-12-15, at 19:02 , Michael Foord wrote:
> 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.)
Even more so with Py3's unpacking supporting more than just head and tail:
>>> a, b, *c, d, e = range(15)
>>> a
0
>>> b
1
>>> d
13
>>> e
14
>>> c
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Alexander's syntax would be nicely parallel to this.
On the other hand, much as Steven I'm not sure how useful it is, especially for tuples.
More information about the Python-ideas
mailing list