Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Open Channel D..." -- Napoleon Solo, The Man From U.N.C.L.E.


devel / comp.lang.python / Re: Negative subscripts

SubjectAuthor
o Re: Negative subscriptsRob Cliffe

1
Re: Negative subscripts

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail
From: rob.cli...@btinternet.com (Rob Cliffe)
Newsgroups: comp.lang.python
Subject: Re: Negative subscripts
Date: Fri, 26 Nov 2021 11:09:03 +0000
Lines: 46
Message-ID: <mailman.21.1637924993.9869.python-list@python.org>
References: <96741f1a-72b3-6551-39b3-f1862c5a80b8@chagford.com>
<ee198109-7f76-f987-8f41-7f18080de51e@btinternet.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de ERTxwtNxqmgXN+5aM+3G9Q5F8Wqb1pDBmhEl5tsj5FvQ==
Return-Path: <rob.cliffe@btinternet.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=btinternet.com header.i=@btinternet.com header.b=Aw1THRWG;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.030
X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'argument': 0.04; 'fairly':
0.05; 'received:192.168.1.64': 0.09; 'theory': 0.09; '"don\'t':
0.16; 'cater': 0.16; 'millman': 0.16; 'wrote:': 0.16; 'to:addr
:python-list': 0.20; 'returns': 0.22; 'actual': 0.25; 'anyone':
0.25; 'else': 0.27; '>>>': 0.28; 'header:User-Agent:1': 0.30;
'program,': 0.31; 'program': 0.31; 'empty': 0.32;
'received:192.168.1': 0.32; 'but': 0.32; 'there': 0.33; 'header
:In-Reply-To:1': 0.34; 'item': 0.35; 'using': 0.37;
'received:192.168': 0.37; 'could': 0.38; 'means': 0.38; 'thanks':
0.38; 'list': 0.39; 'use': 0.39; 'received:213': 0.40; 'wishes':
0.40; 'both': 0.40; 'want': 0.40; 'best': 0.61; 'techniques':
0.62; 'entire': 0.67; 'here"': 0.84; 'rob': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=btinternet.com;
s=btmx201904; t=1637924943;
bh=mOOi+kxACZ/8xEcbg7zdQyMD30WHgHomrIJ0dKde5xo=;
h=Message-ID:Date:MIME-Version:Subject:To:References:From:In-Reply-To;
b=Aw1THRWG1kPP1qFGFUV8Oh6OprxDv2hKobQQwcNRkfIDP9bnjL/QLNsx+X34shJCdf1sFa6dj6ZEoQzbh4zZQMpMIkBPOfzHt6MxKE9Z28iQdY4nm69nUWabrb0WOaAG49aflGPgEOALP5Tsjbr0zBVVSwa5s7/VY1KHan6hN0+l+FIiE7k7evIBs2PGXlwj/XIPjVKjcTUu4wSdXii6DOZK/HioR9TNm7Zma43l/fxpDhmgVrA93hx45U2lnej6hHffolYqk63OSy7OzVMvcxXTzd9zHn4yyyyZ6LvDHM3DGxvn0H76LJxeJh4BDhXEBLShhtxNudK+QoRdjdo0Zw==
Authentication-Results: btinternet.com;
auth=pass (PLAIN) smtp.auth=rob.cliffe@btinternet.com;
bimi=skipped
X-SNCR-Rigid: 613A8CC30B00985B
X-Originating-IP: [86.184.98.10]
X-OWM-Source-IP: 86.184.98.10 (GB)
X-OWM-Env-Sender: rob.cliffe@btinternet.com
X-VadeSecure-score: verdict=clean score=0/300, class=clean
X-RazorGate-Vade: gggruggvucftvghtrhhoucdtuddrgedvuddrhedvgddvfecutefuodetggdotefrodftvfcurfhrohhfihhlvgemuceutffkvffkuffjvffgnffgvefqofdpqfgfvfenuceurghilhhouhhtmecufedtudenucenucfjughrpefkffggfgfuvfhfhfgjtgfgsehtkeertddtfeejnecuhfhrohhmpeftohgsucevlhhifhhfvgcuoehrohgsrdgtlhhifhhfvgessghtihhnthgvrhhnvghtrdgtohhmqeenucggtffrrghtthgvrhhnpedvteduhfetgfevgeeiffelledvuefgieekveevhedutefgveeijeeftdetvedtgeenucfkphepkeeirddukeegrdelkedruddtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehhvghloheplgduledvrdduieekrddurdeigegnpdhinhgvthepkeeirddukeegrdelkedruddtpdhmrghilhhfrhhomheprhhosgdrtghlihhffhgvsegsthhinhhtvghrnhgvthdrtghomhdprhgtphhtthhopehphihthhhonhdqlhhishhtsehphihthhhonhdrohhrgh
X-RazorGate-Vade-Verdict: clean 0
X-RazorGate-Vade-Classification: clean
X-SNCR-hdrdom: btinternet.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Content-Language: en-GB
In-Reply-To: <96741f1a-72b3-6551-39b3-f1862c5a80b8@chagford.com>
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.37
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: <ee198109-7f76-f987-8f41-7f18080de51e@btinternet.com>
X-Mailman-Original-References: <96741f1a-72b3-6551-39b3-f1862c5a80b8@chagford.com>
 by: Rob Cliffe - Fri, 26 Nov 2021 11:09 UTC

You could evaluate y separately:

yval = <long expression>
for item in x[:-yval] if yval else x:
    [do stuff]

or you could do it using the walrus operator:

for item in x[:-yval] if (yval := <long expression>) else x:
    [do stuff]

or, perhaps simplest, you could do

for item in x[:-y or None]: # a value of None for a slice argument means
"don't slice here"
    [do stuff]

Best wishes
Rob Cliffe

On 26/11/2021 09:17, Frank Millman wrote:
> Hi all
>
> In my program I have a for-loop like this -
>
> >>> for item in x[:-y]:
> ...    [do stuff]
>
> 'y' may or may not be 0. If it is 0 I want to process the entire list
> 'x', but of course -0 equals 0, so it returns an empty list.
>
> In theory I can say
>
> >>> for item in x[:-y] if y else x:
> ...    [do stuff]
>
> But in my actual program, both x and y are fairly long expressions, so
> the result is pretty ugly.
>
> Are there any other techniques anyone can suggest, or is the only
> alternative to use if...then...else to cater for y = 0?
>
> Thanks
>
> Frank Millman

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor