Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"It is easier to fight for principles than to live up to them." -- Alfred Adler


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

SubjectAuthor
o Re: Behavior of the for-else constructBarry Scott

1
Re: Behavior of the for-else construct

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: bar...@barrys-emacs.org (Barry Scott)
Newsgroups: comp.lang.python
Subject: Re: Behavior of the for-else construct
Date: Thu, 3 Mar 2022 15:40:45 +0000
Lines: 68
Message-ID: <mailman.120.1646322059.2329.python-list@python.org>
References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<8C70C5F1-A4DA-4FD9-A841-4469ADEBE38D@barrys-emacs.org>
Mime-Version: 1.0 (Mac OS X Mail 15.0 \(3693.60.0.1.1\))
Content-Type: text/plain;
charset=us-ascii
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de lngfaA0Z1v60vLL0o3XYQgE4i5tOZ1HxNa+yTdtwbqZw==
Return-Path: <barry@barrys-emacs.org>
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.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python?': 0.03; '(which':
0.04; 'parallel': 0.05; 'thread': 0.05; 'variable': 0.05; 'loop':
0.07; 'mar': 0.07; 'cc:addr:python-list': 0.09; 'construct': 0.09;
'else:': 0.09; 'from:addr:barry': 0.09; 'received:217.70': 0.09;
'received:gandi.net': 0.09; 'received:mail.gandi.net': 0.09;
'yes.': 0.09; 'cc:no real name:2**0': 0.14; 'url:mailman': 0.15;
'syntax': 0.15; '(when': 0.16; '2022,': 0.16; 'barry': 0.16;
'executed': 0.16; 'flag': 0.16; 'from:addr:barrys-emacs.org':
0.16; 'from:name:barry scott': 0.16; 'iterable': 0.16;
'iteration': 0.16; 'message-id:@barrys-emacs.org': 0.16; 'once.':
0.16; 'sensible': 0.16; 'separately': 0.16; 'separately,': 0.16;
'subject:else': 0.16; 'universe,': 0.16; 'wrote:': 0.16;
'instead': 0.17; "can't": 0.17; 'cc:addr:python.org': 0.20;
'issue': 0.21; 'maybe': 0.22; 'url-ip:188.166.95.178/32': 0.25;
'url-ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'cc:2**0':
0.25; 'url-ip:188.166/16': 0.25; 'so.': 0.26; 'else': 0.27;
'whole': 0.30; 'url-ip:188/8': 0.31; 'think': 0.32; "doesn't":
0.32; 'elements': 0.32; 'empty': 0.32; 'retrieve': 0.32;
"wouldn't": 0.32; 'but': 0.32; 'subject:for': 0.33; 'there': 0.33;
'someone': 0.34; 'header:In-Reply-To:1': 0.34; 'trying': 0.35;
'also,': 0.36; 'really': 0.37; 'using': 0.37; "it's": 0.37;
'means': 0.38; 'read': 0.38; 'list': 0.39; 'block': 0.39; 'on.':
0.39; 'something': 0.40; 'want': 0.40; 'try': 0.40; 'here.': 0.61;
'imagine': 0.64; 'your': 0.64; 'look': 0.65; 'now,': 0.67;
'received:217': 0.67; 'survey': 0.71; 'little': 0.73; 'easy':
0.74; 'yes': 0.76; 'behavior:': 0.84; 'body.': 0.91; 'broke': 0.91
In-Reply-To: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
X-Mailer: Apple Mail (2.3693.60.0.1.1)
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: <8C70C5F1-A4DA-4FD9-A841-4469ADEBE38D@barrys-emacs.org>
X-Mailman-Original-References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
 by: Barry Scott - Thu, 3 Mar 2022 15:40 UTC

> On 3 Mar 2022, at 13:24, computermaster360 <computermaster360@gmail.com> wrote:
>
> I want to make a little survey here.
>
> Do you find the for-else construct useful?

No. I always have to look up what condition the else fires on.

> Have you used it in
> practice?

No.

> Do you even know how it works, or that there is such a thing
> in Python?

Yes (when I read the docs) and yes.

> I have used it maybe once. My issue with this construct is that
> calling the second block `else` doesn't make sense; a much more
> sensible name would be `then`.

There was a thread on this list asking for alternative syntax for the
for: else: that was not taken up. Something like nobreak: instead of else:

>
> Now, imagine a parallel universe, where the for-else construct would
> have a different behavior:
>
> for elem in iterable:
> process(elem)
> else:
> # executed only when the iterable was initially empty
> print('Nothing to process')
>
> Wouldn't this be more natural? I think so. Also, I face this case much
> more often than having detect whether I broke out of a loop early
> (which is what the current for-else construct is for).

>
> Now someone may argue that it's easy to check whether the iterable is
> empty beforehand. But is it really? What if it's an iterator?
> Then one would have to resort to using a flag variable and set it in
> each iteration of the loop. An ugly alternative would be trying to
> retrieve
> the first element of the iterable separately, in a try block before
> the for-loop, to find out whether the iterable is empty. This would of
> course
> require making an iterator of the iterable first (since we can't be
> sure it is already an iterator), and then -- if there are any elements
> -- processing
> the first element separately before the for-loop, which means
> duplicating the loop body. You can see the whole thing gets really
> ugly really quickly...
>
> What are your thoughts? Do you agree? Or am I just not Dutch enough...?

Barry

> --
> https://mail.python.org/mailman/listinfo/python-list
>

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor