<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p><br>
</p>
<br>
<div class="moz-cite-prefix">On 05/07/2018 01:25, Tim Peters wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAExdVNkcVp+FnGfbUZ07bC0BLHNzQF1NHygUVgSfx6oFxn2eww@mail.gmail.com">
<div dir="ltr">
<div class="gmail_quote"><br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">== Pattern 5, two
variables ==<br>
<br>
while True:<br>
m = match()<br>
if not m:<br>
break<br>
j = m.end()<br>
if i == j:<br>
break<br>
...<br>
<br>
replaced with:<br>
<br>
while (m := match()) and (j := m.end()) == i:<br>
</blockquote>
</div>
</div>
</blockquote>
I assume (sorry to be pedantic <span class="moz-smiley-s1"><span>:-)</span></span>)
this is a typo for<br>
while (m := match()) and (j := m.end()) != i:
<blockquote type="cite"
cite="mid:CAExdVNkcVp+FnGfbUZ07bC0BLHNzQF1NHygUVgSfx6oFxn2eww@mail.gmail.com">
<div dir="ltr">
<div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left:1px solid
rgb(204,204,204);padding-left:1ex">
...<br>
<br>
Maybe we reached here the maximum acceptable complexity of a
single<br>
Python line? :-)<br>
</blockquote>
<div><br>
It's at my limit. But, as in an earlier example, I'd be
tempted to do "the obvious part":<br>
<br>
while m:= match():</div>
<div> j = m.end()<br>
if i == j::</div>
<div> break</div>
<div> <br>
</div>
<div>Then the start reads like "while there's something _to_
look at::" and the body of the loop is happily guaranteed
that there is.<br>
<br>
.<br>
</div>
</div>
</div>
</blockquote>
Or you could compromise with this "intermediate density" version
that does two "obvious parts":<br>
<br>
while m:=match():<br>
if (j:=m.end()) == i:<br>
break<br>
<br>
(or as I might write it<br>
<br>
while m:=match():<br>
if (j:=m.end()) == i: break<br>
<br>
).<br>
Some might prefer this as shorter than non-AE version but less dense
than the one-liner. Others might not. <i>De gustibus non est
disputandum.</i><br>
My conclusion: Assignment expressions are - like any other Python
feature - a tool, to be used with discretion and judgement. Not the
start of a competition to see who can write the most
slick/unreadable code.<br>
Regards<br>
Rob Cliffe<br>
</body>
</html>