<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Oct 16, 2016 at 5:34 AM, Sven R. Kunze <span dir="ltr"><<a href="mailto:srkunze@mail.de" target="_blank">srkunze@mail.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On 16.10.2016 07:08, David Mertz wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">In case it wasn't entirely clear, I strongly and vehemently opposed this unnecessary new syntax. It is confusing, bug prone, and would be difficult to teach.</blockquote></span></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
"Whom does he teach? Children?"<br>
Me: "What? No, everybody I think. Why?"<br>
She: "It's easy enough to remember what the star does."<br></blockquote><div><br></div><div>As I've said, the folks I teach are mostly working scientists with doctorates in scientific fields and years of programming experience in languages other than Python. For example, rocket scientists at NASA.</div><div><br></div><div>Now I admit that I don't specifically know how quickly they would pick up on something I've never taught them. But I've written enough teaching materials and articles and books and I have a certain intuition. The way you explained the special case you built up is pretty good, but it's very tailored to making that specific case plausible, and is not general.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">She also asked what would the alternative would look like. I wrote:<br>
"""<br>
>>> from itertools import chain<br>
>>> list(chain.from_iterable((i,i,<wbr>i) for i in range(4)))<br>
[0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]<br>
"""<br>
Her reaction was like: "That's supposed to be easy to remember? I find the star easier."<br></blockquote><div><br></div><div>That is an absolutely terrible construct, obviously. I have to pause and think a while myself to understand what it does. </div><div><br></div><div>It also answers a very different use case than the one that has been mostly discussed in this thread. A much better spelling is:</div><div><br></div><div><div>>>> [i for i in range(4) for _ in range(3)]</div><div>[0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]</div></div><div><br></div><div>For some related uses, itertools.repeat() is very useful.</div><div><br></div><div>But the case that has been discussed far more often is like this:</div><div><br></div><div>>>> listOfLists = [[1,2,3], [4,5,6,7], [8,9]]</div><div>>>> flatten(listOfLists)</div><div><br></div><div>The very long argument is that somehow that would be easier to spell as:</div><div><br></div><div>>>> [*i for i in listOfLists]</div><div><br></div><div>It's just not easier. And there are contrary intuitions that will occur to many people based on the several other related-but-different uses of * for packing/unpacking in other contexts. </div><div><br></div><div>Also, this simplest case might be teachable, but the more general "exactly where can I use that star in a comprehensions" will be far harder to explain plausibly. What's the pattern here?</div><div><br></div><div><div>>>> [(*i,) for i in listOfLists]</div><div>[(1, 2, 3), (4, 5, 6, 7), (8, 9)]</div></div><div>>>> [(i,*i) for i in listOfLists]</div><div>[([1, 2, 3], 1, 2, 3), ([4, 5, 6, 7], 4, 5, 6, 7), ([8, 9], 8, 9)]</div></div><div><div>>>> [(*i,*i) for i in listOfLists]</div><div>[(1, 2, 3, 1, 2, 3), (4, 5, 6, 7, 4, 5, 6, 7), (8, 9, 8, 9)]</div></div><div>>>> [*(i,) for i in listOfLists]</div><div># ... no clear intuition here ...</div><div>>>> [*(*i) for i in listOfLists</div><div># ... even more confusing ...</div><div><br></div><div>Yes! I know those first few are actually doing something different than the proposed new syntax. </div><div><br></div><div>But explaining that to my rocket scientists or your girlfriend in a consistent and accurate way would be a huge challenge. It would mostly come down to "don't do that, it's too confusing."</div><div><br></div>-- <br><div class="gmail_signature">Keeping medicines from the bloodstreams of the sick; food <br>from the bellies of the hungry; books from the hands of the <br>uneducated; technology from the underdeveloped; and putting <br>advocates of freedom in prisons. Intellectual property is<br>to the 21st century what the slave trade was to the 16th.<br></div>
</div></div>