[Python-ideas] Fwd: Fwd: Fwd: unpacking generalisations for list comprehension
Random832
random832 at fastmail.com
Mon Oct 17 16:22:12 EDT 2016
On Mon, Oct 17, 2016, at 14:38, David Mertz wrote:
> What you're saying is EXACTLY 180 deg reversed from the truth. It's
> *precisely* because it doesn't need the extra complication that
> `flatten()`
> is more flexible and powerful. I have no idea what your example is meant
> to do, but the actual correspondence is:
>
> [f(x) for x in flatten(it)]
No, it's not.
For a more concrete example:
[*range(x) for x in range(4)]
[*(),*(0,),*(0,1),*(0,1,2)]
[0, 0, 1, 0, 1, 2]
There is simply no way to get there by using flatten(range(4)). The only
way flatten *without* a generator expression can serve the same use
cases as this proposal is for comprehensions of the *exact* form [*x for
x in y]. For all other cases you'd need list(flatten(...generator
expression without star...)).
More information about the Python-ideas
mailing list