[Python-Dev] Examples for PEP 572 (original) (raw)
Yury Selivanov yselivanov.ml at gmail.com
Wed Jul 4 13:50:48 EDT 2018
- Previous message (by thread): [Python-Dev] Examples for PEP 572
- Next message (by thread): [Python-Dev] Examples for PEP 572
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message (by thread): [Python-Dev] Examples for PEP 572
- Next message (by thread): [Python-Dev] Examples for PEP 572
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]