[Python-ideas] Fwd: Fwd: Fwd: unpacking generalisations for list comprehension

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Oct 15 06:36:28 EDT 2016


Martti Kühne wrote:
> You brush over the fact that *t is not limited to a replacement by a
> comma-separated sequence of items from t, but *t is actually a
> replacement by that comma-separated sequence of items from t INTO an
> external context.

Indeed. In situations where there isn't any context for
the interpretation of *, it's not allowed. For example:

 >>> x = *(1, 2, 3)
   File "<stdin>", line 1
SyntaxError: can't use starred expression here

But

 >>> x = 1, *(2, 3)
 >>> x
(1, 2, 3)

The * is allowed there because it's already in a context
where a comma-separated list has meaning.

-- 
Greg


More information about the Python-ideas mailing list