David Mertz writes:
> On Thu, Jun 17, 2021, 5:24 PM Ben Rudiak-Gould
>
> > Okay, slightly off-topic, but can we *please* allow
> >
> > [*chunk for chunk in list_of_lists]
> >
>
> It is completely non-obvious to me what that would even MEAN. I cannot
> derive anything obvious from other uses of *.
Pretty clearly the * means to unpack the chunk, and substitute extend
for append, no?
result = []
for chunk in list_of_lists:
result.extend(chunk)
You write elsewhere that a loop is an (iterated) assignment (to
chunk), but it's *not* an assignment to result, it's an in-place
modification.
It did take me a bit of thought to come to Ben's intended
interpretation, but I think if you explain it this way, it becomes
obvious to the non-Dutch.
I'll grant that this doesn't *really* work for genexps, but I think of
those as very lazy, very forgetful lists, so WFM.
Serhiy writes that a reason for not allowing this is that you'd want
to allow [x, y for x in l], splicing the x, y values into the result
list. That doesn't make sense to me, for two reasons. x, y already
has a meaning in that context, and the result should be a list of
pairs, each with y as the second element. On the other hand, the
r-value *(x, y) requires a context into which it can be spliced: w, z
= *(x, y) is a syntax error. As the result element in a
comprehension, the context is clearly the comprehension being built.
Perhaps Serhiy meant a similar but different syntax that's problematic?
But if not, I kinda like this.
Steve
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/XL4WP5UOF73UP62N3ZGK62GPTLXZXPTC/
Code of Conduct: http://python.org/psf/codeofconduct/