[Python-ideas] Fwd: Fwd: Fwd: unpacking generalisations for list comprehension
Random832
random832 at fastmail.com
Tue Oct 18 11:23:18 EDT 2016
On Tue, Oct 18, 2016, at 04:01, Daniel Moisset wrote:
> I see some mention that flatten does not cover all cases; but correct
> me if I'm wrong with this statement:
>
> Any case of [*<exp1> for <vars> in <exp2>] could be replaced with
> flatten(<exp1> for <vars> in <exp2>). Where flatten is defined as
>
> def flatten(it):
> return [x for for subit in it for x in subit]
That is correct - though flatten as previously discussed did not return
a list, so list(flatten(...)) was required, though I suppose you could
use [*flatten(...)] - my point was that [especially with the list
constructor] this is significantly more verbose than the proposed
syntax.
More information about the Python-ideas
mailing list