On Wed, Jul 4, 2018 at 1:35 PM Ivan Pozdeev via Python-Dev <python-dev at python.org> wrote: > > On 04.07.2018 11:54, Serhiy Storchaka wrote: > >> while total != (total := total + term): > >> term *= mx2 / (i*(i+1)) > >> i += 2 > >> return total > > > > This code looks clever that the original while loop with a break in a > > middle. I like clever code. But it needs more mental efforts for > > understanding it. > > > > I admit that this is a good example. > > > > There is a tiny problem with it (and with rewriting a while loop as a > > for loop, as I like). Often the body contains not a single break. In > > this case the large part of cleverness is disappeared. :-( > > It took me a few minutes to figure out that this construct actually > checks term == 0. Wow, I gave up on this example before figuring this out (and I also stared at it for a good couple of minutes). Now it makes sense. It's funny that this super convoluted snippet is shown as a good example for PEP 572. Although almost all PEP 572 examples are questionable. Yury
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4