Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

panic: kernel trap (ignored)


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

SubjectAuthor
* Re: Negative subscriptsFrank Millman
`- Re: Negative subscriptsGreg Ewing

1
Re: Negative subscripts

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

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: frank@chagford.com (Frank Millman)
Newsgroups: comp.lang.python
Subject: Re: Negative subscripts
Date: Fri, 26 Nov 2021 15:40:09 +0200
Lines: 29
Message-ID: <mailman.23.1637934336.9869.python-list@python.org>
References: <96741f1a-72b3-6551-39b3-f1862c5a80b8@chagford.com>
<1ed3404c-3eaf-bbdc-56a1-5b4494f495bb@chagford.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: news.uni-berlin.de 5/bzWOMpv/9+dVXkOEb66ACvBltEkngOI1Mx7dLZY9ow==
Return-Path: <frank@chagford.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.005
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'fairly': 0.05; 'neat':
0.09; 'theory': 0.09; 'cater': 0.16; 'from:addr:chagford.com':
0.16; 'from:addr:frank': 0.16; 'from:name:frank millman': 0.16;
'message-id:@chagford.com': 0.16; 'millman': 0.16;
'received:196.35': 0.16; 'received:196.35.198': 0.16;
'received:197.90': 0.16; 'received:197.90.32': 0.16;
'received:197.90.32.26': 0.16; 'received:synaq.com': 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;
'ideas': 0.28; 'header:User-Agent:1': 0.30; 'am,': 0.31;
'program,': 0.31; 'program': 0.31; 'empty': 0.32; 'but': 0.32;
'there': 0.33; 'appreciated.': 0.34; 'header:In-Reply-To:1': 0.34;
'item': 0.35; 'thanks': 0.38; 'list': 0.39; 'use': 0.39; 'both':
0.40; 'want': 0.40; 'techniques': 0.62; 'entire': 0.67; 'choose':
0.67; 'received:196': 0.69; 'from.': 0.84
Authentication-Results: synaq.com; iprev=fail smtp.remote-ip=197.90.32.26;
auth=pass (PLAIN) smtp.auth=frank@chagford.com;
arc=none
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Content-Language: en-US
In-Reply-To: <96741f1a-72b3-6551-39b3-f1862c5a80b8@chagford.com>
X-Red-Router: yes
X-SYNAQ-Pinpoint-Information: Please contact SYNAQ for more information
X-SYNAQ-Pinpoint-ID: 1mqbSb-000nHN-PU
X-SYNAQ-Pinpoint: No virus infections found
X-SYNAQ-Pinpoint-SpamCheck: not spam, SpamAssassin (not cached, score=-3.793,
required 9, autolearn=disabled, ALL_TRUSTED -1.00,
DCC_REPUT_00_12 -0.80, NICE_REPLY_A -1.99)
X-Pinpoint-From: frank@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: <1ed3404c-3eaf-bbdc-56a1-5b4494f495bb@chagford.com>
X-Mailman-Original-References: <96741f1a-72b3-6551-39b3-f1862c5a80b8@chagford.com>
 by: Frank Millman - Fri, 26 Nov 2021 13:40 UTC

On 2021-11-26 11:17 AM, 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 for all the replies. A selection of neat ideas for me to choose from.

Much appreciated.

Frank

Re: Negative subscripts

<j0d9d2Fb5s2U1@mid.individual.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: greg.ewing@canterbury.ac.nz (Greg Ewing)
Newsgroups: comp.lang.python
Subject: Re: Negative subscripts
Date: Sat, 27 Nov 2021 12:37:06 +1300
Lines: 24
Message-ID: <j0d9d2Fb5s2U1@mid.individual.net>
References: <96741f1a-72b3-6551-39b3-f1862c5a80b8@chagford.com>
<1ed3404c-3eaf-bbdc-56a1-5b4494f495bb@chagford.com>
<mailman.23.1637934336.9869.python-list@python.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 8m8trDRX1KooP8CiaprDXwqZSc3o5pt+4xzerqlKWaAsuT9PXB
Cancel-Lock: sha1:YLrrFu2q+lSQLCTmkOGssVXCfgA=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:78.0)
Gecko/20100101 Thunderbird/78.4.0
In-Reply-To: <mailman.23.1637934336.9869.python-list@python.org>
Content-Language: en-US
 by: Greg Ewing - Fri, 26 Nov 2021 23:37 UTC

> On 2021-11-26 11:17 AM, Frank Millman wrote:
>> Are there any other techniques anyone can suggest, or is the only
>> alternative to use if...then...else to cater for y = 0?

x[:-y or None]

Seems to work:

>>> l
['a', 'b', 'c', 'd', 'e']
>>> def f(x): return l[:-x or None]
....
>>> f(3)
['a', 'b']
>>> f(2)
['a', 'b', 'c']
>>> f(1)
['a', 'b', 'c', 'd']
>>> f(0)
['a', 'b', 'c', 'd', 'e']

--
Greg


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

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor