Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

There can be no twisted thought without a twisted molecule. -- R. W. Gerard


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

SubjectAuthor
o Re: Behavior of the for-else constructRob Cliffe

1
Re: Behavior of the for-else construct

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: rob.cli...@btinternet.com (Rob Cliffe)
Newsgroups: comp.lang.python
Subject: Re: Behavior of the for-else construct
Date: Fri, 4 Mar 2022 01:43:38 +0000
Lines: 83
Message-ID: <mailman.145.1646358230.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>
<5d362e45-1b83-f7a0-8c46-e3b8e720d366@btinternet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de sCAykN9SmtY0POoOfnMJ1gNJhs2J/E/Gla2iQ67CN7MA==
Return-Path: <rob.cliffe@btinternet.com>
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=btinternet.com header.i=@btinternet.com header.b=B/OYrAcR;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.010
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'looks': 0.02; 'this:':
0.03; '2022': 0.05; 'parallel': 0.05; 'e.g.': 0.07; 'loop': 0.07;
'mar': 0.07; 'angelico': 0.09; 'construct': 0.09; 'elif': 0.09;
'else:': 0.09; 'received:192.168.1.64': 0.09; 'chrisa': 0.16;
'construct.': 0.16; 'grasp': 0.16; 'idea.': 0.16; 'matched': 0.16;
'subject:else': 0.16; 'unfortunate': 0.16; 'useless': 0.16;
'using.': 0.16; 'wrote:': 0.16; 'to:addr:python-list': 0.20;
'language': 0.21; 'basically': 0.22; 'exception': 0.22; 'fri,':
0.22; '(and': 0.25; 'saying': 0.25; 'anyone': 0.25; 'creating':
0.27; "isn't": 0.27; 'else': 0.27; 'chris': 0.28; 'it,': 0.29;
'header:User-Agent:1': 0.30; 'takes': 0.31; 'comment': 0.31;
'raise': 0.31; 'think': 0.32; "doesn't": 0.32; 'fine.': 0.32;
'keyword': 0.32; 'python-list': 0.32; 'received:192.168.1': 0.32;
'but': 0.32; "i'm": 0.33; 'subject:for': 0.33; 'header:In-Reply-
To:1': 0.34; 'item': 0.35; 'meaning': 0.35; 'following': 0.35;
'people': 0.36; 'those': 0.36; 'really': 0.37; "it's": 0.37;
'hard': 0.37; 'received:192.168': 0.37; 'means': 0.38; 'put':
0.38; 'read': 0.38; 'quite': 0.39; 'single': 0.39; 'enough': 0.39;
'use': 0.39; 'block': 0.39; 'break': 0.39; 'still': 0.40;
'place.': 0.40; 'received:213': 0.40; 'want': 0.40; 'try': 0.40;
'remember': 0.61; 'here.': 0.61; "there's": 0.61; 'finally': 0.62;
'point.': 0.62; 'here': 0.62; 'true': 0.63; 'ever': 0.63; 'pass':
0.64; "you'd": 0.64; 'similar': 0.65; 'body': 0.67; 'attached':
0.68; 'right': 0.68; 'items': 0.68; 'ignore': 0.71; 'yes': 0.76;
'clause': 0.84; 'code)': 0.84; 'massive': 0.84; 'means,': 0.84;
'remind': 0.84; 'rob': 0.84; '"do': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com;
s=btmx201904; t=1646358222;
bh=2eOuHyM+6z4Vwd5ALxIRyI9JzI2pJdf3dQEc60r/0P0=;
h=Message-ID:Date:MIME-Version:Subject:To:References:From:In-Reply-To;
b=B/OYrAcRzBJTdC8IFd7ew2UsQtBzvwY4Uh0hBg4Sj81d06vtepgHoC05GjKiyWgQxKaQm2Z+i2FfsHMhvQJGPIKT2QdEFPLL67XHGzsKDpVxgJjEnBVvFiFh9nOWgSKhX0iuFTtk0joGOxKWkm7GaazGK4p27hb+VNvUJhBSzUTivM1a3ArCh1eAbA8A5zVZBCQVKFTXZTOviuEjfuFaNb2r6P/EVpBF4OK7Wa7N5T2cPJu7lVQTXZS/WyGheDaZxzCD/1M4h71TXu4V1fovmSBmuwFIf/rJ4aFtqN+lRXnBcpiN7eN23Eowqs1qkIPvZzJX4cMngZBPH0RgGUgu+A==
Authentication-Results: btinternet.com;
auth=pass (PLAIN) smtp.auth=rob.cliffe@btinternet.com;
bimi=skipped
X-SNCR-Rigid: 6139429017FE52FA
X-Originating-IP: [86.173.124.29]
X-OWM-Source-IP: 86.173.124.29 (GB)
X-OWM-Env-Sender: rob.cliffe@btinternet.com
X-VadeSecure-score: verdict=clean score=0/300, class=clean
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvvddruddtjedgfeekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuueftkffvkffujffvgffngfevqffopdfqfgfvnecuuegrihhlohhuthemuceftddunecunecujfgurhepkfffgggfuffvfhfhjggtgfesthejredttdefjeenucfhrhhomheptfhosgcuvehlihhffhgvuceorhhosgdrtghlihhffhgvsegsthhinhhtvghrnhgvthdrtghomheqnecuggftrfgrthhtvghrnhepudeiffelleetudekjefgfeekieekteevgfehffdtieeluefhueejveevffffgedvnecukfhppeekiedrudejfedruddvgedrvdelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghloheplgduledvrdduieekrddurdeigegnpdhinhgvthepkeeirddujeefrdduvdegrddvledpmhgrihhlfhhrohhmpehrohgsrdgtlhhifhhfvgessghtihhnthgvrhhnvghtrdgtohhmpdhnsggprhgtphhtthhopedupdhrtghpthhtohepphihthhhohhnqdhlihhsthesphihthhhohhnrdhorhhg
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
X-SNCR-hdrdom: btinternet.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
Content-Language: en-GB
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: <5d362e45-1b83-f7a0-8c46-e3b8e720d366@btinternet.com>
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: Rob Cliffe - Fri, 4 Mar 2022 01:43 UTC

On 04/03/2022 00:43, Chris Angelico wrote:
> On Fri, 4 Mar 2022 at 11:14, Rob Cliffe via Python-list
> <python-list@python.org> wrote:
>> I find it so hard to remember what `for ... else` means that on the very
>> few occasions I have used it, I ALWAYS put a comment alongside/below the
>> `else` to remind myself (and anyone else unfortunate enough to read my
>> code) what triggers it, e.g.
>>
>> for item in search_list:
>> ...
>> ... break
>> else: # if no item in search_list matched the criteria
> A "break" statement always takes you to the line following the current
> loop construct. The "else" block is part of the current loop
> construct. It's no more a "no-break" block than the body of the for
> loop is a "no-break" body here:
>
> for item in stuff:
> if condition: break
> frobnicate(item) # if no previous item matched the condition
>
>> You get the idea.
>> If I really want to remember what this construct means, I remind myself
>> that `else` here really means `no break`. Would have been better if it
>> had been spelt `nobreak` or similar in the first place.
> Maybe, but I think that obscures the meaning of it; "finally" isn't
> quite right either (in a try block, you'd hit a finally block whether
> you raise an exception or not), but I think it's closer. Creating a
> new language keyword is an incredibly high cost.
>
> 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,
Yes but you have to remember what for-else means even to grasp that point.
> 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,
Not for me, I'm afraid.
> 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.
>
> ChrisA

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor