Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The linuX Files -- The Source is Out There. -- Sent in by Craig S. Bell, goat@aracnet.com


devel / comp.lang.python / Re: Behavior of the for-else construct

SubjectAuthor
o Re: Behavior of the for-else constructRoel Schroeven

1
Re: Behavior of the for-else construct

<mailman.157.1646384748.2329.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17336&group=comp.lang.python#17336

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: roe...@roelschroeven.net (Roel Schroeven)
Newsgroups: comp.lang.python
Subject: Re: Behavior of the for-else construct
Date: Fri, 4 Mar 2022 10:05:44 +0100
Lines: 62
Message-ID: <mailman.157.1646384748.2329.python-list@python.org>
References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<YiFCPlGC+2aRIR0K@shallowsky.com>
<21739669.459456.1646348879560@mail.yahoo.com>
<e3544242-cd54-05d3-2101-5b9fedc1c13e@btinternet.com>
<CAPTjJmpa4t5nEJYnohkam6JVVZ6H3V-2av_UKtvspiws7Usxyw@mail.gmail.com>
<f104ed5c-bcbf-08e1-e0b0-3b8c71547d66@roelschroeven.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de /iXJ7LInX563d5ItYw0d+Qnjy3Btlj/oYAUtIRT35jwA==
Return-Path: <roel@roelschroeven.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=roelschroeven.net header.i=@roelschroeven.net
header.b=UdMmbr3R; dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.034
X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'looks': 0.02; 'this:':
0.03; 'parallel': 0.05; 'loop': 0.07; 'construct': 0.09; 'elif':
0.09; 'else:': 0.09; 'franklin': 0.16; 'iirc': 0.16; 'mention,':
0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16;
'received:internal': 0.16; 'received:messagingengine.com': 0.16;
'schreef': 0.16; 'subject:else': 0.16; 'useless': 0.16; 'using.':
0.16; 'says': 0.17; 'to:addr:python-list': 0.20; 'language': 0.21;
'basically': 0.22; 'saying': 0.25; 'else': 0.27; 'chris': 0.28;
'it,': 0.29; 'header:User-Agent:1': 0.30; 'think': 0.32;
"doesn't": 0.32; 'concept': 0.32; 'fine.': 0.32; 'but': 0.32;
"i'm": 0.33; 'subject:for': 0.33; 'header:In-Reply-To:1': 0.34;
'item': 0.35; 'particularly': 0.35; 'received:66': 0.35; 'people':
0.36; 'those': 0.36; 'really': 0.37; "it's": 0.37; 'hard': 0.37;
'could': 0.38; 'single': 0.39; 'use': 0.39; 'break': 0.39;
'still': 0.40; 'case.': 0.40; 'something': 0.40; 'want': 0.40;
'here.': 0.61; "there's": 0.61; 'me.': 0.62; 'true': 0.63; 'ever':
0.63; 'once': 0.63; 'pass': 0.64; 'definition': 0.64; 'company':
0.64; 'his': 0.65; 'attached': 0.68; 'items': 0.68; 'ignore':
0.71; 'jones': 0.78; 'clause': 0.84; 'conveys': 0.84; 'massive':
0.84; 'rob': 0.84; '"do': 0.91; 'criticism': 0.91; 'friend,': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
roelschroeven.net; h=cc:content-transfer-encoding:content-type
:date:date:from:from:in-reply-to:in-reply-to:message-id
:mime-version:references:reply-to:sender:subject:subject:to:to;
s=fm2; bh=u00+h0hKZiYm1KHGzwUly4cUz6xryRTeXNGdyz45wLU=; b=UdMmb
r3R2nCrzaxzFu/XdNS4QYDMKgRsONlXQ87weGyjIs/dam7BRW1hShys0SgWekSre
6YOSWRLKmG2QUri9trSGf5e9LHXAn6TOpUPPAQm0ajtjOMQzxDYrFvft9ZI10aGZ
D67GFOetWftUS18VoucOt5EMXTdFrmCuosKx/XN9fbwP9m+esfVnyFP93I/5lYHU
8mcgIKt9KmRYQcy5AFuhIAyaW09b8/fXMAchMfJUiaDv/RUmYxW3G87v5aFO9zUA
jTwUkU8qKcXOrlHtJCvLLSqDddmVlRXTMvMZjgKLYW2JRcKZ+sQS9HKU4+ysq4wU
c8zQHmk3hrrEQ/U6A==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
messagingengine.com; h=cc:content-transfer-encoding:content-type
:date:date:from:from:in-reply-to:in-reply-to:message-id
:mime-version:references:reply-to:sender:subject:subject:to:to
:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=
fm2; bh=u00+h0hKZiYm1KHGzwUly4cUz6xryRTeXNGdyz45wLU=; b=B8ogrbZb
2wjeuwuyZ8p+IdcXT1QfIFX553TwtrThYfPiy9nTDkJs/FT+0imk759RrFYmtYwu
yuGwtj27hKVcLz57Q+Bqv46bmePGcwzHnMv5DOBbXWH+UkKeyF1z6h3AziSeAnQb
YRiYnLVeMppsWd1jsOXcvh5lku6z2Bvu+gV84CHhDgtCApex9xLS43rIEDtUhFpW
4Pdpf3Fxq12LD8DRLy25H/Ay2821Tdm6wAoxpWcr3bkyXGsE2SpI4IPbDUHUXDVb
R2M5huSJV/S8edoap63dHjZfOhTcw6UakW96FDIIImC3y6xo5hhfXgz2oHSpMrjt
he3Q6bsfv23A/Q==
X-ME-Sender: <xms:atYhYs2pwgb2UzUa5XSfdASZ4TnE8l3CRtsFhs1wUN4vXHvN4CPg8w>
<xme:atYhYnGWYlz0i0wQLrw6JaqLS4VWx--Exs_zgi3eBdiSWNHiiiDlZ3Rhc2HxZ0SYJ
EtzW-6HJU45>
X-ME-Received: <xmr:atYhYk7sr47NlQ3seKnZVndTXCCzJE7ygVivEx4BzN7ZuSHQvQBFAMGznHiavbzgtZClEPP_YjgwKmP4rgFMpMWEWSIzDJXBfR2xjFXV-3YgBoI>
X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddruddtkecutefuodetggdotefrodftvfcurf
hrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecuuegr
ihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttd
efjeenucfhrhhomheptfhovghlucfutghhrhhovghvvghnuceorhhovghlsehrohgvlhhs
tghhrhhovghvvghnrdhnvghtqeenucggtffrrghtthgvrhhnpedttdfgieeihfehheffff
dttdfggedvgeelgeefvdeihfektdffvdegfefhhfdtgfenucevlhhushhtvghrufhiiigv
pedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehrohgvlhesrhhovghlshgthhhrohgvvh
gvnhdrnhgvth
X-ME-Proxy: <xmx:atYhYl0dAZBfcfbCBLVm0cNW7G3bUcdf-KPFC275_06T_gyQ9txCOQ>
<xmx:atYhYvHS2kRE42D61ejLFdfrGyAj42-N9V8KcZlUKVPVT5yC7TXgVg>
<xmx:atYhYu_ywt8MQCfrd-qO3aDavrYjegvsDNrLx_qz1ssGe97EE7AjQg>
<xmx:atYhYmzGPoHuy0r0vEOUwHepRPjau_HZOiqLZTnTcYtb7T-2ShG88Q>
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Content-Language: nl
In-Reply-To: <CAPTjJmpa4t5nEJYnohkam6JVVZ6H3V-2av_UKtvspiws7Usxyw@mail.gmail.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <f104ed5c-bcbf-08e1-e0b0-3b8c71547d66@roelschroeven.net>
X-Mailman-Original-References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<YiFCPlGC+2aRIR0K@shallowsky.com>
<21739669.459456.1646348879560@mail.yahoo.com>
<e3544242-cd54-05d3-2101-5b9fedc1c13e@btinternet.com>
<CAPTjJmpa4t5nEJYnohkam6JVVZ6H3V-2av_UKtvspiws7Usxyw@mail.gmail.com>
 by: Roel Schroeven - Fri, 4 Mar 2022 09:05 UTC

Op 4/03/2022 om 1:43 schreef Chris Angelico:
> Think of it like this:
>
> for item in search_list:
> if condition: pass
> else:
> print("Condition not true for this item")
>
> for item in search_list:
> if condition: break
> else:
> print("Condition not true for any item")
>
> There's a parallel here. Since a for-else loop is basically useless
> without an if-break construct inside it, the else clause can be
> thought of as the else on a massive if/elif chain:
>
> if stuff[0].is_good:
> print("This item is good", stuff[0])
> elif stuff[1].is_good:
> print("This item is good", stuff[1])
> ...
> ...
> elif stuff[n].is_good:
> print("This item is good", stuff[n])
> else:
> print("All items are bad")
>
> As a loop, this looks like this:
>
> for item in stuff:
> if item.is_good:
> print("This item is good", item)
> break
> else:
> print("All items are bad")
>
> The else is attached to the for so that it compasses ALL the if
> statements, but it's still broadly saying "do this when we don't hit
> the 'if' condition".
>
> Whether that's a sufficient mnemonic, I don't know [...]
Certainly not for me. It could work for the specific use case you
mention, but nothing in the definition restricts it to be used for that
use case. As Rob Cliffe says in one of his posts, a for-loop can be
terminated with "break" for many  conceptually different reasons. A
mnemonic that only works for one specific use case, even if it's the
most used one, doesn't work as a mnemonic for the general concept for me.

> [...], but it doesn't
> really matter; the construct is useful to those of us who want it, and
> if other people ignore it, that's fine. Nobody ever said you had to
> use or understand every single feature of the language you're using.
True, still, I agree with people who think nobreak would have been
better because it better conveys the intention. IIRC Raymond Hettinger
once said something like that too, so I'm in good company I guess.

--
"Honest criticism is hard to take, particularly from a relative, a friend,
an acquaintance, or a stranger."
-- Franklin P. Jones

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor