Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Clothes make the man. Naked people have little or no influence on society. -- Mark Twain


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

SubjectAuthor
o RE: Behavior of the for-else constructSchachner, Joseph

1
RE: Behavior of the for-else construct

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: Joseph.S...@Teledyne.com (Schachner, Joseph)
Newsgroups: comp.lang.python
Subject: RE: Behavior of the for-else construct
Date: Thu, 3 Mar 2022 17:25:54 +0000
Lines: 39
Message-ID: <mailman.128.1646328430.2329.python-list@python.org>
References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
<BN8PR14MB285101A6BF0271714A46FAA2F5049@BN8PR14MB2851.namprd14.prod.outlook.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: base64
X-Trace: news.uni-berlin.de JtORkmS48xlO6Q68PVnn9AAcOkPJwPvlWGDCuUPrxV7w==
Return-Path: <prvs=054aeafbf=Joseph.Schachner@teledyne.com>
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.001
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python?': 0.03; '(which':
0.04; '2022': 0.05; 'joseph': 0.05; 'parallel': 0.05; 'variable':
0.05; 'loop': 0.07; 'construct': 0.09; 'else:': 0.09; 'it)': 0.09;
'received:nam11-bn8-obe.outbound.protection.outlook.com': 0.09;
'received:namprd14.prod.outlook.com': 0.09; '(when': 0.16;
'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;
'used:': 0.16; 'useful.': 0.16; '\xf0\x9f\x98\x8a': 0.16; "can't":
0.17; 'to:addr:python-list': 0.20; 'issue': 0.21; 'maybe': 0.22;
'to:name:python-list@python.org': 0.24; 'skip:- 10': 0.25;
'behavior': 0.26; 'sensitive': 0.26; 'so.': 0.26; 'request.':
0.28; 'whole': 0.30; '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; 'march': 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; 'block': 0.39; 'received:unknown': 0.39; 'want':
0.40; 'try': 0.40; 'here.': 0.61; 'from:': 0.62; 'to:': 0.62;
'imagine': 0.64; 'your': 0.64; 'now,': 0.67; 'survey': 0.71;
'little': 0.73; 'easy': 0.74; 'yes': 0.76; 'business': 0.77;
'sent:': 0.78; 'behavior:': 0.84; 'rare': 0.84; 'body.': 0.91;
'broke': 0.91
IronPort-Data: A9a23:JDChSak21qUM9zLJBBgYZIPo5gzIJ0RdPkR7XQ2eYbSJt1+Wr1Gzt
xIYD2rTbPvfZmP1eN9xPNvl8kwC6MSEydNkQVc9+Cg3Ey4T+ZvOCOrFEkqhZCn6wu/rFRo9s
51GMoGowOMcFyeG+k/1auCJQV1Uj/zgqm/UUbacUsxJbVY4Dn9n03qPosZh6mJSqYHR7zil5
JWj+6UzBHf/g2QuajlMsPrZwP9SlK+aVA0w7wVWic9j7Ae2e0k9VPrz8onochMU6qENdgKLb
76rIIORpws1zD90Yj+RqYsXR2VWKlLk0apivVINM0SqqkAqSiXfSc/XPtJEAatco2zhc9ycV
LyhHHF/IOskFvSkpQgTb/VXO3BhLP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1643702400"; d="scan'208";a="66340462"
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=bMfNdYYpf+34GA0YXNS62uUHZOTYfnpzoHAKDAyx9UvliKtmuZtMiAwqw1LgjbzUjBKpZapSzM4hPu6yJy9Ml37epzchNSWJdkc7sPl8DIjsoFIUGq44z1iWnoq/9Gf8UrciTz/cFYSTzHSbYaLwBYw6SwzyT76lpGJCWtIOSzX30VVmXLuPm8mg0MFgxpAiJRykIHD/hKysfSaCtCsHVCRfI77ySKjf2O4SDoGCiGeRMN64qZ5PylPlzzEjaZCna+m/TRVX4Elx8vadJKaVNkM3/BMK60umFDXj1QlrQRYThiQZFFLWIS0uIlD0vyTowBL/h+Bc5xiqIV96F0GezA==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com;
s=arcselector9901;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1;
bh=BdCKHTpsrBPE6y6qWa7dWwx2IBUY+KUXUiIXfFg/ulw=;
b=mqqdmO9VX4NJk1C7VKhfkVq5FMUI8lF+2c9Ya7319FzjosVdGoVVHAmA2fHPXrrjibRnWxyUN2GbFLlQ0mVR638L6D38snYnbNOLc1jYKMjTPsT0BDYh1E1rOIvJ/sPDWqK2jp0z2H3Elgaw4w4keExfmNFL+4l0fLwRO4e7+WXcQZJr7yHDodjSYnhpUAuM/0umwXuIUn7TFBYb/to4/KdnjUD564ZDy8MDlCWQeJG+tkAEZZlnJUKsvnZi0IWpwtSCqZxUTZ7vAP7EczJbD2xAQNFKhsLn9DKPDlSbcmCJqdrnk8OwagPtPPLcyat5R3oSYDcxIe1bWCfCP24jMg==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=teledyne.com; dmarc=pass action=none header.from=teledyne.com;
dkim=pass header.d=teledyne.com; arc=none
Thread-Topic: Behavior of the for-else construct
Thread-Index: AQHYLyDKHCyf5B/NjUWQcoqmeqVnbayt6GQw
In-Reply-To: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
msip_labels: MSIP_Label_0d178f3f-9d62-4d87-b8af-200399509a39_Enabled=true;
MSIP_Label_0d178f3f-9d62-4d87-b8af-200399509a39_SetDate=2022-03-03T17:25:52Z;
MSIP_Label_0d178f3f-9d62-4d87-b8af-200399509a39_Method=Standard;
MSIP_Label_0d178f3f-9d62-4d87-b8af-200399509a39_Name=Company Sensitive;
MSIP_Label_0d178f3f-9d62-4d87-b8af-200399509a39_SiteId=e324592a-2653-45c7-9bfc-597c36917127;
MSIP_Label_0d178f3f-9d62-4d87-b8af-200399509a39_ActionId=daa32f75-31c3-4224-8909-a28bd1337117;
MSIP_Label_0d178f3f-9d62-4d87-b8af-200399509a39_ContentBits=2
authentication-results: dkim=none (message not signed)
header.d=none;dmarc=none action=none header.from=Teledyne.com;
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: 42c2ff8d-90ab-4073-fd78-08d9fd3adf28
x-ms-traffictypediagnostic: BY5PR14MB3972:EE_
x-microsoft-antispam-prvs: <BY5PR14MB3972F8AF5338A97B772BC834F5049@BY5PR14MB3972.namprd14.prod.outlook.com>
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: SRi3mS3odCtIY5qbyCObTr+Hy/S0Njkdps2R1blAKo4rIIjkfmjvak72I1TYKyTb/R5mJ0IIxqYo+j5/KhUbjByP8VeIANKd6SrVeROQ8KwIRjhsRAeXVbB77OZT4KgKqwDPtBAADC1QTKA3ez7NJ86A3uhyB02P5UtIs0MvWfNl9qXyXYimSF37BsYI5ouGKw/eiUY3t0Npbh3D2uAiJ691Gmmkx7G6eMtlwYi4WuHgdLGD8a4XyJ9VoQSitKkdAWh5smmb4XEEurV+NHZgvOujGdaLMUaIHREVz39vVQmmM9Sgpo+FmXFRoEA+luUwDyMVk0D5MSNibhcW/wUsv0mOQlsDfeVUgfiEuxVZfR7Jqw4TQHq4ipgSskcJVMox1WwT4g7ZknaBZK+/2f4JH1kCiEXfVJR/3NsZaajuZaRIag7wXfmnQdynxA0m7I1Wv5ixCnHJ8Yt/9Ehw/prtr4B11vXzFW7VDf5i9jY5p+Ixtoz1IdwTUAipvcFzhks921anxABqwW6XiHIDnUVBkMgKxuAnASpkNp4iGUTarxZIWVEg315jBzoIoPiAAU0MGdZGi3bZw2GTw9F/g6SfQ0/yvCoVDPGrK3pRXUh0Tj0XKkfb2CZcQAJWZVIcTindKCpOlcbPa77Lnl8wy6DnUfaND4J6ihilQ1D9jSHWymfqLv2irtn3CcRzj4RtDryPoS2ouJYv2CyqLY7OiuuUXw==
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:BN8PR14MB2851.namprd14.prod.outlook.com; PTR:; CAT:NONE;
SFS:(13230001)(366004)(498600001)(83380400001)(66946007)(66556008)(66476007)(76116006)(64756008)(66446008)(8676002)(2906002)(86362001)(55016003)(33656002)(38100700002)(52536014)(38070700005)(8936002)(122000001)(5660300002)(6506007)(7696005)(9686003)(53546011)(26005)(186003)(71200400001)(110136005);
DIR:OUT; SFP:1102;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: 81FXEhOsNkl8t9M/Id8LT4RJ3Tsz4vqWeGP+3Gab98rO/
dN244cSz1tnd+78EZw+RAZhVSZy0Iz/Im3IUmTOKCMd6H
FhP17U1djNC8NnH3s6HlHVKbbbcZIx1LMItHRPTPmNqj7
gsnr4sKXG6Y0T3rKPSuAczUZHOGwhyr6CM8kXefDUnYyL
3V4rWedCZ1rW0Dv/bSpHPqP1B4olP0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ZxSXKUWixF
0Xe+8ecDxtK2zj35+IDhRgWRmUYcf7eJBuB+BeMXtaDgT
6AaJFHrWi8Et7kwZGCseAtKCgQUOcQGmJY8n23/7YlTAI
jWQ1JIb8o7LSTSw8XvXrEV42AJhDioGC9tTYqwqsPxRXB
fV5pVWsXeeCcHBQ6UkJ2EgdWIrNjQlnAr8SdKouBuXsTb
F1wSoFviHD/oFK66Yh62O8v1jWbJuvAQZzUg26jrzREEM
cStOlkmAFyFsXkQCIZ8Tmj2GMZT6mPBi/cULyo1c5eUtn
F/+eEG82qglX3fTDQN+crDe3UXnSaRi9jJ1an94b6xva1
Uyv2rf46SQUsqH9guaPcWIRBzFDUREzQsymZTKsUr5o7I
cLsK+R+QbKEI7DsruezxsfMjSeKN8MVfNRRd7ij3ZhKgA
8JlszDJsDKvaqLpwNunIA==
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: BN8PR14MB2851.namprd14.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: 42c2ff8d-90ab-4073-fd78-08d9fd3adf28
X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Mar 2022 17:25:54.2009 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: e324592a-2653-45c7-9bfc-597c36917127
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: PwCNrfx2Q6/orA3HOoyNFt2Tum8G9qSzAP8stQ84MizJ1P+OtGaTYB3uODtf6s+UoTdpV0hcEKpvX6UoLJZPMbTgiwmtaDfhEmUwmAGzTns=
X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR14MB3972
X-OriginatorOrg: Teledyne.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: <BN8PR14MB285101A6BF0271714A46FAA2F5049@BN8PR14MB2851.namprd14.prod.outlook.com>
X-Mailman-Original-References: <CALq4Z0-fJk-HOu0ka2kPrOioPYAh3e3zbziwetUDmAAx1U1LMw@mail.gmail.com>
 by: Schachner, Joseph - Thu, 3 Mar 2022 17:25 UTC

Useful: On rare occasions (when a loop has a "break" in it)
Used: Yes
Know how it works: Yes
Even is such a thing: Yes
Your suggestion: Also useful. Will require a different keyword. I don't know what that would be. "finally" is available 😊 Write up a feature request.
--- Joseph S.

Teledyne Confidential; Commercially Sensitive Business Data
-----Original Message-----
From: computermaster360 <computermaster360@gmail.com>
Sent: Thursday, March 3, 2022 8:24 AM
To: python-list@python.org
Subject: Behavior of the for-else construct
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...?

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor