<div dir="auto"><div>FWIW, the nested loop over a single item is already in the language for 15 years or something. It's not that ugly, certainly not enough to need a new 'let' or 'where' keyword that basically does exactly the same thing with 3 fewer characters.<br><div class="gmail_extra"><br><div class="gmail_quote">On Feb 23, 2018 10:04 PM, David Mertz <<a href="mailto:mertz@gnosis.cx">mertz@gnosis.cx</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div><div class="gmail_extra"><br><div class="gmail_quote">On Feb 23, 2018 9:26 PM, "Steven D'Aprano" <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="quoted-text">Given a potentially expensive DRY violation like:<br></div>
<br>
    [(function(x), function(x)+1) for x in sequence]<br>
<br>
there are at least five ways to solve it.<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">A 6th way is to wrap the expensive function in @lru_cache() to make it non-expensive.</div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">    [(a, a+1) for x in sequence for a in [function(x)]]<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">It's funny to me how many people, even the BDFL, have said this is tricky to reason about or recognize. I didn't think of it all by myself, but saw it somewhere years ago. It seemed obvious once I saw it. Since then it's something I do occasionally in my code without much need for thought.</div><div dir="auto"><br></div><div dir="auto"><br></div></div></blockquote></div><br></div></div></div>