Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

The Macintosh is Xerox technology at its best.


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

SubjectAuthor
o Re: Behavior of the for-else constructChris Angelico

1
Re: Behavior of the for-else construct

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: ros...@gmail.com (Chris Angelico)
Newsgroups: comp.lang.python
Subject: Re: Behavior of the for-else construct
Date: Fri, 4 Mar 2022 18:18:51 +1100
Lines: 43
Message-ID: <mailman.155.1646378344.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>
<CAPTjJmp0BQ0y5atoJS5+NK2zt3RQr7G4r=5=XHzGq8SCcXcUYA@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de MX4hihWe07IBKgssjEacpwimLh/DJfYl5+GWcoMj6C8Q==
Return-Path: <rosuav@gmail.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=gmail.com header.i=@gmail.com header.b=Yy79SThN;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'traceback': 0.04; '(most':
0.05; '2022': 0.05; 'last):': 0.05; 'variable': 0.05; 'e.g.':
0.07; 'loop': 0.07; 'mar': 0.07; 'construct': 0.09; 'else:': 0.09;
'chrisa': 0.16; 'demonstrated': 0.16; 'dieter': 0.16;
'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16;
'idea.': 0.16; 'loop?': 0.16; 'matched': 0.16; 'named.': 0.16;
'subject:else': 0.16; 'unfortunate': 0.16; 'wrote:': 0.16;
'to:addr:python-list': 0.20; 'fri,': 0.22; "what's": 0.22; '(and':
0.25; 'anyone': 0.25; 'else': 0.27; '>>>': 0.28; 'this?': 0.29;
'it,': 0.29; 'comment': 0.31; '"",': 0.32; 'message-
id:@mail.gmail.com': 0.32; 'subject:for': 0.33; 'header:In-Reply-
To:1': 0.34; 'received:google.com': 0.34; 'item': 0.35;
'following': 0.35; 'from:addr:gmail.com': 0.35; 'cases': 0.36;
'really': 0.37; 'received:209.85': 0.37; 'hard': 0.37; 'file':
0.38; 'means': 0.38; 'put': 0.38; 'read': 0.38; 'received:209':
0.39; '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; 'perfectly': 0.69;
'sequence': 0.69; 'means,': 0.84; 'none"': 0.84; 'remind': 0.84;
'rob': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:references:in-reply-to:from:date:message-id:subject:to;
bh=KzuDtMWr+C8x85T9nU+/fNLHW0T2s6/QjVyABGdUCEk=;
b=Yy79SThNEMzwdBFdIXC6JOBXksjfb8dhl0ipRL+b3ubEtVGn2aOCbbVza8u0dn9wDx
tk9wxnIUT7Wz868lCuzIHPr6wo0LZ7wlLEevB+5oWWfDkXUTbpECAZwU5Ks+S1DaaP5Y
GcuEmgZqjqCN2akz8nJ5Og2gd8HVB4wYzMTeysxT4/2MJhAbpCBhueYEpn/FLsvYazwL
Blvcp5d4rH0WQnPWbsfaAOje0Ei8mzxBhzMfcaHWDmhZqTKJ0li/XiP808HNbOMdBJ/g
3fUsSy6o81QAwKsHrf4HK9aP0iQMUu48CPDHKkxIyhnmo6o7Nhp4R8jMHpRFRlp6BEzO
sXbg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:references:in-reply-to:from:date
:message-id:subject:to;
bh=KzuDtMWr+C8x85T9nU+/fNLHW0T2s6/QjVyABGdUCEk=;
b=k6W7LqmugcvT7AAy9GfZC1g+Kfq3xP9sp5u83f2vPiR2TaFX8QqACM0cVMAfrvsvEt
fwF8QQXJKpti/4yOJFIU65U6ZZoYgZhd3BMPp0vfO+D5wF3Sd5qhumasMOAhZwukxe7p
UAeMOIQWQrLWOY+MaQ63XZ/ZHrGNE62uNFYuxPQUkLW75Auf+D7eNYCuvpwMZ0QZbjHs
AYyduh6J5aSPQT0yydW+KSJIfbFsASSgMbh3PWim0u5rFqij3tIA7TsH9z/A8ueexXQm
9Y2OAy1hMI5tVOYbXvVdWKjX4G2/w3L4k7uIC/Yp9V98kZD+qfrBIncBJDBRUjs/+eI0
rwDQ==
X-Gm-Message-State: AOAM530wPRjoBzncSX58r8/5pbGwDThDozMw3yHED4mkh0r2p5u65bli
4GkxS608EQet51BzYrKjgEhzY9qRtJzjo4ukl25AadEt
X-Google-Smtp-Source: ABdhPJyFtKKcPv8om/ZY+IpqdCCimVHKtiIbdRL1QMhZew7uugBSwKyfmjoBOhbAVyDVRK01Q5XuheiZdEtySdAvPfc=
X-Received: by 2002:a5d:6a09:0:b0:1f0:6530:2e45 with SMTP id
m9-20020a5d6a09000000b001f065302e45mr2594628wru.160.1646378342475; Thu, 03
Mar 2022 23:19:02 -0800 (PST)
In-Reply-To: <25121.48093.26762.592197@ixdm.fritz.box>
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: <CAPTjJmp0BQ0y5atoJS5+NK2zt3RQr7G4r=5=XHzGq8SCcXcUYA@mail.gmail.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>
<25121.48093.26762.592197@ixdm.fritz.box>
 by: Chris Angelico - Fri, 4 Mar 2022 07:18 UTC

On Fri, 4 Mar 2022 at 18:13, Dieter Maurer <dieter@handshake.de> wrote:
>
> 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.

What's the point of this? Why not just put "i = None" after the loop?

ChrisA

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor