<p dir="ltr">But the proposal has explicit syntax that point the reader to the fact that the invariant doesn't hold. Same as other unpacking occurences:</p>
<p dir="ltr">[x, *y] </p>
<p dir="ltr">The invariant does not hold. And that's explicit. </p>
<p dir="ltr">Elazar</p>
<br><div class="gmail_quote"><div dir="ltr">בתאריך יום ב׳, 17 באוק' 2016, 21:16, מאת Brendan Barnwell <<a href="mailto:brenbarn@brenbarn.net">brenbarn@brenbarn.net</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 2016-10-17 10:32, Steven D'Aprano wrote:<br class="gmail_msg">
> In a list comprehension, we expect the invariant that the number of<br class="gmail_msg">
> items produced will equal the number of loops performed. (Less if there<br class="gmail_msg">
> are any "if" clauses.) There is one virtual append per loop. You cannot<br class="gmail_msg">
> get the behaviour you want without breaking that invariant: either the<br class="gmail_msg">
> append has to be replaced by extend, or you have so insert an extra loop<br class="gmail_msg">
> into your mental picture of comprehensions.<br class="gmail_msg">
><br class="gmail_msg">
> Yet again, for emphasis: I understand that you don't believe that<br class="gmail_msg">
> invariant is important, or at least you are willing to change it. But<br class="gmail_msg">
> drop the pretense that this is an obvious extension to the well-<br class="gmail_msg">
> established behaviour of list comprehensions and sequence unpacking.<br class="gmail_msg">
<br class="gmail_msg">
It seems to me that this difference is fundamental. The entire point<br class="gmail_msg">
of this type of generalization is to break that invariant and allow the<br class="gmail_msg">
number of elements in the result list to vary independently of the<br class="gmail_msg">
number of iterations in the comprehension.<br class="gmail_msg">
<br class="gmail_msg">
It seems that a lot of this thread is talking at cross purposes,<br class="gmail_msg">
because the specifics of the syntax don't matter if you insist on that<br class="gmail_msg">
invariant. For instance, there's been a lot of discussion about whether<br class="gmail_msg">
this use of * is or isn't parallel to argument unpacking or assignment<br class="gmail_msg">
unpacking, or whether it's "intuitive" to some people or all people.<br class="gmail_msg">
But none of that matters if you insist on this invariant. If you insist<br class="gmail_msg">
on this invariant, no syntax will be acceptable; what is at issue is the<br class="gmail_msg">
semantics of enlarging the resulting list by more than one element.<br class="gmail_msg">
<br class="gmail_msg">
Now, personally, I don't insist on that invariant. I would certainly<br class="gmail_msg">
like to be able to do more general things in a list comprehension, and<br class="gmail_msg">
many times I have been irritated by the fact that the one-item-per-loop<br class="gmail_msg">
invariant exists. I'm not sure whether I'm in favor of this particular<br class="gmail_msg">
syntax, but I'd like to be able to do the kind of things it allows. But<br class="gmail_msg">
doing them inherently requires breaking the invariant you describe.<br class="gmail_msg">
<br class="gmail_msg">
--<br class="gmail_msg">
Brendan Barnwell<br class="gmail_msg">
"Do not follow where the path may lead. Go, instead, where there is no<br class="gmail_msg">
path, and leave a trail."<br class="gmail_msg">
--author unknown<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
Python-ideas mailing list<br class="gmail_msg">
<a href="mailto:Python-ideas@python.org" class="gmail_msg" target="_blank">Python-ideas@python.org</a><br class="gmail_msg">
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" class="gmail_msg" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br class="gmail_msg">
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" class="gmail_msg" target="_blank">http://python.org/psf/codeofconduct/</a><br class="gmail_msg">
</blockquote></div>