Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Why are there always boycotts? Shouldn't there be girlcotts too? -- argon on #Linux


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

SubjectAuthor
* Behavior of the for-else constructcomputermaster360
+- Re: Behavior of the for-else constructMichael F. Stemper
`- Re: Behavior of the for-else constructJon Ribbens

1
Behavior of the for-else construct

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: computer...@gmail.com (computermaster360)
Newsgroups: comp.lang.python
Subject: Behavior of the for-else construct
Date: Thu, 3 Mar 2022 14:24:05 +0100
Lines: 39
Message-ID: <mailman.114.1646313859.2329.python-list@python.org>
References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: news.uni-berlin.de xLFEHwBgM+rgex121v7LUwlT585vMCLhpRO4raWhmAjA==
Return-Path: <computermaster360@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=f5+QpGR8;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.009
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python?': 0.03; '(which':
0.04; 'parallel': 0.05; 'variable': 0.05; 'loop': 0.07;
'construct': 0.09; 'else:': 0.09; 'executed': 0.16; 'flag': 0.16;
'iterable': 0.16; 'iteration': 0.16; 'once.': 0.16; 'sensible':
0.16; 'separately': 0.16; 'separately,': 0.16; 'subject:else':
0.16; 'universe,': 0.16; "can't": 0.17; 'to:addr:python-list':
0.20; 'issue': 0.21; 'maybe': 0.22; 'so.': 0.26; 'whole': 0.30;
'think': 0.32; "doesn't": 0.32; 'elements': 0.32; 'empty': 0.32;
'retrieve': 0.32; "wouldn't": 0.32; 'message-id:@mail.gmail.com':
0.32; 'but': 0.32; 'subject:for': 0.33; 'there': 0.33; 'someone':
0.34; 'received:google.com': 0.34; 'trying': 0.35;
'from:addr:gmail.com': 0.35; 'also,': 0.36; 'really': 0.37;
'using': 0.37; "it's": 0.37; 'received:209.85': 0.37; 'means':
0.38; 'received:209': 0.39; 'block': 0.39; 'want': 0.40; 'try':
0.40; 'here.': 0.61; 'imagine': 0.64; 'your': 0.64; 'now,': 0.67;
'survey': 0.71; 'little': 0.73; 'easy': 0.74; 'behavior:': 0.84;
'received:209.85.167.177': 0.84; 'received:mail-
oi1-f177.google.com': 0.84; 'body.': 0.91; 'broke': 0.91
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112;
h=mime-version:from:date:message-id:subject:to;
bh=e+ATnQ9d7Cm6gRg40rAq3iFlAU31SQuGZkh+nkUonJ4=;
b=f5+QpGR8ju0V0426+sPW4SlpLB52HWnO9J2zoCKPKY1un3PmKUz3mxoJZ+nevkWv3+
PPTvG7fVFj32QjyhyvLhgeb4IzQjcNKUHk0gbm2KzM6WYsk8ko1zu3fyva1WMo8iMrUT
JKHv+OWo4THpjf+GnFQuNqe9iHyjNSVapyzRUN7qlCHkyRZXtop9LTsZrHAdxJAoe+SR
ERPC6gqF8uINYPzZ3/Y/rBfpksBDL3z8pZL+C2aRsMFezU0OduUU/bBOTIjWnTdGjNCN
XhpjcruwX1Yh2mzZJZw0A+x4uo+BYhha9PMHROKUmstchG4/Y8xGjYGrHRvO6bmWcQHQ
CyvA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112;
h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
bh=e+ATnQ9d7Cm6gRg40rAq3iFlAU31SQuGZkh+nkUonJ4=;
b=ifKf2UG0UvbuIu/iI4FCMiq7sxL8AJq/qRy91OcRK4xVGxZtZUT/yYbU6KVCbY9EPW
Diw9R3aAZmqoYo/FvaeyX9K6B7RsdvSkm00iSL5/63u3+SpI7sjXFqAWJ3cHOTMWD5cw
xJJdDv+EkJcMMI2KoitujB8r82gm04O6hDO/Pwhem3U5C424EerZGMacQhCw3yVUvXQL
ErJMsvaAgV1Ii7+p12B7dnzt+AsTlA667J12yF82lgiXuZQM6Ru2DVuXsPjR7Gw/4nI+
dfZIwf4/h+OkPISh+Q/9VbUYH4egv5nnrBPIn/7aoh9eAnA85ywdzm0ByELCafPtzavN
EG8Q==
X-Gm-Message-State: AOAM531hSadgcJ7FGlC/vJSHghvIPSnYU3dJXWGIYaoyBZKfkR9oo4xS
KRzdI04qnCn8j22CdA/Xpo1DZRlg99PJr0LPm5JU+Ry/joU=
X-Google-Smtp-Source: ABdhPJzWTyz9uf60uQkaZ3ep8pR0nTNsGA5GxMv0h6H/7K5iJZRJIwuTpheCeHekyblxiuJ559SpABNtw8uV/gdqpa0=
X-Received: by 2002:a05:6808:118e:b0:2d4:6fe7:6bd7 with SMTP id
j14-20020a056808118e00b002d46fe76bd7mr4543253oil.146.1646313856050; Thu, 03
Mar 2022 05:24:16 -0800 (PST)
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: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
 by: computermaster360 - Thu, 3 Mar 2022 13:24 UTC

I want to make a little survey here.

Do you find the for-else construct useful? Have you used it in
practice? Do you even know how it works, or that there is such a thing
in Python?

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`.

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...?

Re: Behavior of the for-else construct

<svqhri$1pv$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: michael....@gmail.com (Michael F. Stemper)
Newsgroups: comp.lang.python
Subject: Re: Behavior of the for-else construct
Date: Thu, 3 Mar 2022 08:03:30 -0600
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <svqhri$1pv$1@dont-email.me>
References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<mailman.114.1646313859.2329.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 3 Mar 2022 14:03:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="385d355543bf490f46dcaf1fb33c28af";
logging-data="1855"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+UvR1/PZHiZJrfVVOa9fAjMeD4mrJwid0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:vfYfVUBsbaKde/9w1ZSPfDKbhRQ=
In-Reply-To: <mailman.114.1646313859.2329.python-list@python.org>
Content-Language: en-US
 by: Michael F. Stemper - Thu, 3 Mar 2022 14:03 UTC

On 03/03/2022 07.24, computermaster360 wrote:
> I want to make a little survey here.
>
> Do you find the for-else construct useful? Have you used it in
> practice? Do you even know how it works, or that there is such a thing
> in Python?

I only found out about it within the last year or so. I've used it
probably half-a-dozen times. It seems quite elegant to me.

--
Michael F. Stemper
A preposition is something you should never end a sentence with.

Re: Behavior of the for-else construct

<slrnt21l7n.2go.jon+usenet@raven.unequivocal.eu>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jon+use...@unequivocal.eu (Jon Ribbens)
Newsgroups: comp.lang.python
Subject: Re: Behavior of the for-else construct
Date: Thu, 3 Mar 2022 14:47:19 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <slrnt21l7n.2go.jon+usenet@raven.unequivocal.eu>
References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<mailman.114.1646313859.2329.python-list@python.org>
Injection-Date: Thu, 3 Mar 2022 14:47:19 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="8e4f81e073c04b2bf7730d1380392236";
logging-data="26051"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/IhN2+CmYxIH4nne0ul9cUpe8XTwm8wD4="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:uoBNfvFYDOuWWW9z33vyBqDs6Lk=
 by: Jon Ribbens - Thu, 3 Mar 2022 14:47 UTC

On 2022-03-03, computermaster360 <computermaster360@gmail.com> wrote:
> Do you find the for-else construct useful? Have you used it in
> practice?

Yes, I use it frequently.

> 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`.

You are not the only person with this opinion, although personally
I have the opposite opinion. I think of 'for...else' as being
a search for something that matches a condition, and the 'else'
block is if no item is found that matches. If you think of it like
that, the syntax makes perfect sense.

> 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).

I guess peoples' needs vary. I can't even remember the last time
I've needed something as you suggest above - certainly far less
often than I need 'for...else' as it is now.

> What are your thoughts? Do you agree?

I don't agree. But it doesn't really matter if anyone agrees or not,
since there is no chance whatsoever that a valid Python syntax is
suddenly going to change to mean something completely different, not
even in "Python 4000" or whatever far-future version we might imagine.

This exact topic was discussd in November 2017 by the way, under the
subject heading "Re: replacing `else` with `then` in `for` and `try`".
I'm not sure any particular conclusion was reached though except that
some people think 'else' is more intuitive and some people think
'then' would be more intuitive.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor