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

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Oct 14 01:57:23 EDT 2016


Random832 wrote:

> [*map(math.exp, t) for t in [(1, 2), (3, 4)]]
> 
> [*(math.exp(x) for x in t) for t in [(1, 2), (3, 4)]]

Or more simply,

   [math.exp(x) for t in [(1, 2), (3, 4)] for x in t]

I think this brings out an important point. While it
would be nice to allow * unpacking in comprehensions
for consistency with displays, it's not strictly
necessary, since you can always get the same effect
with another level of looping.

So it comes down to whether you think added conistency,
plus maybe some efficiency gains in some cases, are worth
making the change.

-- 
Greg


More information about the Python-ideas mailing list