Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

I'm all for computer dating, but I wouldn't want one to marry my sister.


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

SubjectAuthor
o Re: Behavior of the for-else constructDieter Maurer

1
Re: Behavior of the for-else construct

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: die...@handshake.de (Dieter Maurer)
Newsgroups: comp.lang.python
Subject: Re: Behavior of the for-else construct
Date: Fri, 4 Mar 2022 08:12:29 +0100
Lines: 37
Message-ID: <mailman.154.1646377956.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>
<25121.48093.26762.592197@ixdm.fritz.box>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de icDnOALWgPQw1VLSnfoJUAp/9ysx8/NLuVFGsaqTCS4Q==
Return-Path: <dieter@handshake.de>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=none reason="no signature";
dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status: OK 0.012
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'traceback': 0.04; '(most':
0.05; 'last):': 0.05; 'variable': 0.05; 'e.g.': 0.07; 'loop':
0.07; 'cc:addr:python-list': 0.09; 'construct': 0.09; 'else:':
0.09; 'cc:no real name:2**0': 0.14; 'demonstrated': 0.16; 'idea.':
0.16; 'matched': 0.16; 'named.': 0.16; 'subject:else': 0.16;
'unfortunate': 0.16; 'cc:addr:python.org': 0.20; 'received:de':
0.23; '(and': 0.25; 'cc:2**0': 0.25; 'anyone': 0.25; 'else': 0.27;
'>>>': 0.28; 'it,': 0.29; 'comment': 0.31; '"",': 0.32;
'subject:for': 0.33; 'header:In-Reply-To:1': 0.34; 'item': 0.35;
'following': 0.35; 'cases': 0.36; 'really': 0.37; 'hard': 0.37;
'file': 0.38; 'means': 0.38; 'put': 0.38; 'read': 0.38; 'enough':
0.39; 'use': 0.39; 'break': 0.39; 'wrote': 0.39; 'place.': 0.40;
'want': 0.40; 'remember': 0.61; 'here': 0.62; 'pass': 0.64;
'involve': 0.64; 'similar': 0.65; 'header:Received:6': 0.67;
'perfectly': 0.69; 'sequence': 0.69; 'charset:iso-8859-1': 0.73;
'....': 0.76; 'means,': 0.84; 'received:88': 0.84; 'remind': 0.84;
'rob': 0.84
In-Reply-To: <e3544242-cd54-05d3-2101-5b9fedc1c13e@btinternet.com>
X-Mailer: VM 8.0.12-devo-585 under 21.4 (patch 24) "Standard C" XEmacs Lucid
(x86_64-linux-gnu)
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: <25121.48093.26762.592197@ixdm.fritz.box>
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>
 by: Dieter Maurer - Fri, 4 Mar 2022 07:12 UTC

Rob Cliffe wrote at 2022-3-4 00:13 +0000:
>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
>
>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.

One of my use cases for `for - else` does not involve a `break`:
the initialization of the loop variable when the sequence is empty.
It is demonstrated by the following transscript:

```pycon
>>> for i in range(0):
.... pass
....
>>> i
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'i' is not defined
>>> for i in range(0):
.... pass
.... else: i = None
....
>>> i
>>>
```

For this use case, `else` is perfectly named.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor