Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Insufficient facts always invite danger. -- Spock, "Space Seed", stardate 3141.9


devel / comp.lang.python / Re: New assignmens ...

SubjectAuthor
o Re: New assignmens ...Christman, Roger Graydon

1
Re: New assignmens ...

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: dvl...@psu.edu (Christman, Roger Graydon)
Newsgroups: comp.lang.python
Subject: Re: New assignmens ...
Date: Mon, 25 Oct 2021 16:47:45 +0000
Lines: 85
Message-ID: <mailman.34.1635180469.23718.python-list@python.org>
References: <MN2PR02MB68461EB83EC01991C31D6752A8839@MN2PR02MB6846.namprd02.prod.outlook.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de zOjvZ10dyXkxMLkgYdFVCATly5AAO+M8pvzgD47dGqfQ==
Return-Path: <dvl@psu.edu>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="1024-bit key; unprotected key"
header.d=psu.edu header.i=@psu.edu header.b=jv9ZRjbx;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.040
X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'message:': 0.03; 'stream':
0.04; 'variable': 0.05; 'all!': 0.07; 'loop': 0.07; 'pep': 0.07;
'text/plain;': 0.07; 'ui&quot;,': 0.07; '+0200': 0.09;
'apparently': 0.09; 'example:': 0.09; '&gt;': 0.14; '(west': 0.16;
'antoon': 0.16; 'calculations': 0.16; 'condition.': 0.16; 'ctr':
0.16; 'duplication': 0.16; 'initialize': 0.16; 'niche': 0.16;
'pardon': 0.16; 'roger': 0.16; 'typing': 0.16; 'value?': 0.16;
'values?': 0.16; 'yield': 0.16; 'wrote:': 0.16; 'reduce': 0.19;
'to:addr:python-list': 0.20; 'code': 0.23; 'to:name:python-
list@python.org': 0.24; '(and': 0.25; 'skip:- 10': 0.25; 'seems':
0.26; 'follows:': 0.26; 'function': 0.27; 'purpose': 0.28;
'recently': 0.29; 'it,': 0.29; 'whole': 0.30; 'code,': 0.31;
'takes': 0.31; '&quot;segoe': 0.31; 'expand': 0.32; 'obtain':
0.32; 'performed': 0.32; 'programmers': 0.32; 'tool.': 0.32;
'but': 0.32; 'there': 0.33; 'particular': 0.33; 'requires': 0.34;
'cases': 0.36; 'count': 0.36; 'mon,': 0.36; 'really': 0.37;
'using': 0.37; 'class': 0.37; 'others': 0.37; 'way': 0.38;
'means': 0.38; 'necessary': 0.39; 'date:': 0.39; 'list': 0.39;
'use': 0.39; 'neither': 0.39; 'advantage': 0.40; 'both': 0.40;
'something': 0.40; 'want': 0.40; 'higher': 0.60; 'font-family:':
0.60; 'sample': 0.61; 'from:': 0.62; 'to:': 0.62; '0px;': 0.63;
'skip:b 10': 0.63; 'down': 0.64; 're:': 0.64;
'received:namprd02.prod.outlook.com': 0.64; 'your': 0.64; 'saw':
0.65; 'benefit': 0.65; 'tool': 0.65; 'required': 0.65; 'less':
0.65; 'right': 0.68; 'margin:': 0.68; 'operations': 0.68; 'adds':
0.69; 'counter': 0.69; 'forcing': 0.69; 'highlight': 0.69;
'received:nam12-bn8-obe.outbound.protection.outlook.com': 0.69;
'sans-serif;': 0.70; 'instead,': 0.70; 'truly': 0.70; '2021':
0.71; 'longer': 0.71; 'charset:iso-8859-1': 0.73; '(such': 0.84;
'furthermore': 0.84; 'one:': 0.84; 'pennsylvania': 0.84;
'received:40.107.237': 0.84; 'remind': 0.84; 'skip:& 50': 0.84;
'mind,': 0.93
ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none;
b=Ple082kwQKMxzq93n/6IEQ1bT5mYQp5TO/DkNVOrcYIfOc1epggJYl11S5fpUsqvs06o+Y/ewHhjZIjS3jcPEXI74l4l/soTKuHKQOPEJBZTBta/WLIHJUL7D3CWktzjmF7AYDHRBLjaMPlsBBKGsqD5Tj0mm4HC247GD59+xdEEPRweMvfLUuXbEkf7X3/8Nro9QuqIbZepUTTfd8tbH/3jNFhHv9DZI/ajUeFTmNPy/T3P+ncS3M8krZcT6GH+u18pyngEIKo01i9065n1Ggbu0y3aQn1+3ukRRjMP3Mha/nSRFxoND8qH36Z/tKCfhK/KF6k7pHNnXRPXgx9kyg==
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=y4C3xv38KgwljhULNdjMFS7yMQ0+9a99dFJzbjOpIb4=;
b=VApZOPAE1pxtI9krcC5RPWtSkcZwNpYrhnf62E9H/Njj+H/bHe+wU67hGYx+co+Fs7ODrCJkGzvqj7zYgsqwvqoPsP0tTbPnN0Ioz4rs9AR4IeaACsLte+Nevw0ojnxuwUtjW+Nag/qwivjQ7YFdWIKDt+KscM9WPmmAUjmdV95VEIDAy/Tek6AHePJzAb/isG058UH0M9W9sbYRr8HCr4U3q3949+vQSHGliL4iYwPSRIL8IlKOCNibaOFVjbAAY0ZIcK/I8oJsuUKfcIPjYRjoaYPbW0o2ydazMVpRl0LKMrtFiT3t0CPqZtrl3kN3MZ/c7gbsXDhNRAUn3Bcuaw==
ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass
smtp.mailfrom=psu.edu; dmarc=pass action=none header.from=psu.edu; dkim=pass
header.d=psu.edu; arc=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=psu.edu; s=selector1;
h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck;
bh=y4C3xv38KgwljhULNdjMFS7yMQ0+9a99dFJzbjOpIb4=;
b=jv9ZRjbxj02z7vRHU5bqgLXSjtHsYmQXiWrPBVKYJ8QjWjyk9G0DHXe2AfuZ5pPYm2purCZrDsrSlBhU8umXe4ZWQ0eJwJI4SDed4Ys+oLUxoUSPBFakNVZgjYPTKbqlWHFCb/NGYIN9ko3LmouioE+6l0vGMdITNxkT6P8vzx8=
Thread-Topic: New assignmens ...
Thread-Index: AQHXyb1OdnaKXKjB6UeQ4K2bYbBCHg==
Accept-Language: en-US
Content-Language: en-US
X-MS-Has-Attach:
X-MS-TNEF-Correlator:
suggested_attachment_session_id: 6420b68c-4b4f-c590-aee0-4fe57a66404e
authentication-results: python.org; dkim=none (message not signed)
header.d=none;python.org; dmarc=none action=none header.from=psu.edu;
x-ms-publictraffictype: Email
x-ms-office365-filtering-correlation-id: f716d18b-edfd-4b3b-0834-08d997d72bde
x-ms-traffictypediagnostic: MN2PR02MB5870:
x-microsoft-antispam-prvs: <MN2PR02MB58700602EC7FD18503A3E5BBA8839@MN2PR02MB5870.namprd02.prod.outlook.com>
x-ms-oob-tlc-oobclassifiers: OLM:10000;
x-ms-exchange-senderadcheck: 1
x-ms-exchange-antispam-relay: 0
x-microsoft-antispam: BCL:0;
x-microsoft-antispam-message-info: pHkAk7tTUkCYKAqpQTWeIOh2nbGMrSP9qUhgOWm6bDiw+17y2bu0Uj1uSkEEGa/O2IFiA88X32Ds7pvcX/DFFANjjQGVN0K8ZaKV3CefdPU6QzbZL/ntORk6pmP6Ii619A9QQbGHkSE6Z8gVg6VfQJziZbXHfBh6jLZm0DrE+wb+UGdtzmhTO3k9qGcqZ4PSUDMYkwrmdi6CuVhCE8yG0eN+STny3ZxjasaHAUGYZfmeay6jEiNNFGQGQ/VBC6c/Sn8RBAqu6XmPyW0JD+dKW0vtNCYcYQIiR0mwkU3szdhOsnQGCQQf1qI8ElEx0sgKNyrO5/O8hjC1Dy/C2gU2psv5fNy3SnoQxC3QLS/QakNXhCzzqHNK6n8Iemce2V1RQgPWBZ0x2jLuQ/XL/owF4vaunMnxR+h1XRyFUtQu2ji98kXFeqiJEJVHm2RScX39S/l+3juT/5lRbFYl9dBj5mRxH2uCDowFbNRaNJHczWhEJdnEiOqqlUdss1XLB6h7UG+BEocCZACZDDvnrnib6wOSrSq/dK9crInr3U4C6XcWQpOmsLwOsWDDZcX8/AqULG/8KSlnN2y6MoXqiOKszWkewWY0k+8sO0vz+fPDX226dE3zkin228LLWCzmT605M70BLOfzUqWcKdCzZKfFfXfwLfnXEMngQIUWb+PZTlYJ6IiYyjGqFb7XWlC5VBehRT9k4GZ/Ewb/0hcOvwcV/g==
x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:;
IPV:NLI; SFV:NSPM; H:MN2PR02MB6846.namprd02.prod.outlook.com; PTR:; CAT:NONE;
SFS:(4636009)(366004)(19627405001)(8676002)(64756008)(66556008)(76116006)(33656002)(66946007)(66446008)(83380400001)(122000001)(75432002)(38070700005)(3480700007)(316002)(786003)(2906002)(66476007)(52536014)(7696005)(508600001)(38100700002)(186003)(9686003)(19627235002)(55016002)(6506007)(26005)(6916009)(5660300002)(7116003)(8936002)(53546011)(86362001)(71200400001);
DIR:OUT; SFP:1102;
x-ms-exchange-antispam-messagedata-chunkcount: 1
x-ms-exchange-antispam-messagedata-0: W1+sD99nM7q25gnU9hlf1FL+c2Cm1I3ibn1Yvnt6JUE3jkSScGfVfdqTm6
//14O8nyvwIbfbakgjUo2mD+OVrt5VgPCMjEpXWtwJK8or/ZEZyvWN0N1V
r/THyLVuV0u2eT8qIWKUs6EolE56BOynZtVesZdKoyVlsHy2Y6+ILaB4/A
Hux1ZHIyN537ZD8wvX6qYfkxWvUhUgFrWPqyQBu5Ewrs/nuTJ2P0neOp/i
d49wvM9SNkjbzj6x4OKZiwKUtmuR74A2ij9E/kz84VkQ6vFzUp6xb1KIMv
Wll9kiWTJvuGXMdHZYvddwSoS9u681gSl2dk23JFalfK7vJ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ytI+HX7Gn7p2HwQBWoOoBvKmHYJ6SzFOCdcO
NGiMcA7WGuXv198Xmz+rTJFwPE3oFD0rsXiFJP7HSpZH4miP8oxRJjCWUf
YMuk80CoXoVAYBsLQm6Yn5kelrvQ0KVvUG7n8N40C2h/K2DmjQ==
X-OriginatorOrg: psu.edu
X-MS-Exchange-CrossTenant-AuthAs: Internal
X-MS-Exchange-CrossTenant-AuthSource: MN2PR02MB6846.namprd02.prod.outlook.com
X-MS-Exchange-CrossTenant-Network-Message-Id: f716d18b-edfd-4b3b-0834-08d997d72bde
X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Oct 2021 16:47:45.9071 (UTC)
X-MS-Exchange-CrossTenant-fromentityheader: Hosted
X-MS-Exchange-CrossTenant-id: 7cf48d45-3ddb-4389-a9c1-c115526eb52e
X-MS-Exchange-CrossTenant-mailboxtype: HOSTED
X-MS-Exchange-CrossTenant-userprincipalname: PX3yh252X3mXxhdicwSWMHt4QvNntSOgC86fChzY9lUGs4t2BiMnyjUok/wZKb14
X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR02MB5870
X-Content-Filtered-By: Mailman/MimeDel 2.1.35
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.35
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: <MN2PR02MB68461EB83EC01991C31D6752A8839@MN2PR02MB6846.namprd02.prod.outlook.com>
 by: Christman, Roger Gra - Mon, 25 Oct 2021 16:47 UTC

Message: 8
Date: Mon, 25 Oct 2021 11:20:52 +0200
From: Antoon Pardon <antoon.pardon@vub.be>
To: python-list@python.org
Subject: Re: New assignmens ...
Message-ID: <5761dd65-4e87-8b8c-1400-edb8212048db@vub.be>
Content-Type: text/plain; charset=utf-8; format=flowed
On 25/10/2021 11:20, Anton Pardon wrote:
> Suppose I would like to write a loop as follows:

> while ((a, b) := next_couple(a, b))[1]:
> do needed calculations

> What I can do is write it as follows:

> while [tmp := next_couple(a,b), a := tmp[0], b := tmp[1]][-1]:
> do needed calculations

> I really don't see what is gained by "forcing" me to right the second code over the first.

No, nobody is forcing you to right it the second way over the first.
Nobody is forcing you to use the walrus operator at all!

Instead, I would recommend something more like:

while b:
do needed calculations
(a,b) = next_couple(a,b)

This requires even less typing than what you had before!

But it also raises a whole lot of problems with this particular example:
-- neither a nor b is defined in your sample while loop. It seems you would
need to initialize a and b before your while loop (and mine)
-- is b truly a boolean value, or are you short-cutting some other value?
-- are a and b truly necessary parameters to next_couple, or are they just
there to remind the function of its previous return values?
If the latter, poerhaps you want a stream or list or something with yield

This example (and some of the others I have seen) just highlight how
programmers will take advantage of any new tool to help them write
worse code than if they did not have the tool. In my mind, the walrus
operator was designed to serve a particular niche case like this one:

while (x := input()) > 0:

where not having the operator required duplicating the input() operation
both before the loop and at the end of the loop -- or more complicated
cases where some additional operations had to be performed to get
that test value for the while condition (such as getting the b out of (a,b)).

But the walrus only adds a benefit if it is there to avoid the duplication
of the code that is used to obtain that test condition. This next_couple
example does not qualify, since apparently (a,b) are initialized by some
other means (and not be a call to next_couple with undefined values)

Or the other abuse I saw recently about using the walrus operator:

while (self.ctr := self.ctr-1) > 0:

-- there was no compelling reason for a loop counter to be a class variable
(anyone who peeks at this counter when the loop is down would only see a zero)
-- this requires self.ctr to be initialized to a value one higher than the first
meaningful value (start at 11 if you want to count down from 10)
So my recommended alternative, which furthermore also takes less typing:

while ctr > 0:
...
ctr = ctr-1

TL;DR: The Walrus operator serves the purpose as described in its PEP
just as it is, and I see no compelling reason to expand its use.
It is there to reduce code size by eliminating a duplication of code,
If the code you write using the walrus operator is longer or more
complicated than the code would be without it, you are misusing it.

Roger Christman
Pennsylvania State University

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor