Deutsch   English   Français   Italiano  
<v4ld02$3mt2j$6@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna <HenHanna@devnull.tb>
Newsgroups: comp.lang.python,comp.lang.lisp
Subject: Re: diff1(x) in Python: True if all adjacent items differ by 1, False
 otherwise.
Date: Sat, 15 Jun 2024 17:52:18 -0700
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <v4ld02$3mt2j$6@dont-email.me>
References: <v4kuk5$3k353$1@dont-email.me> <8734pd7v1r.fsf@nightsong.com>
 <v4lanu$3mt2j$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 16 Jun 2024 02:52:19 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="35c3840a03f107b42fbf945be62926e9";
	logging-data="3896403"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18ssq4n6FnShLaiRqBKbtwZ2hR7Ot6c5Gc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:WXZHzx8r4rLodypdSuZ+RlFw45M=
Content-Language: en-US
In-Reply-To: <v4lanu$3mt2j$1@dont-email.me>
Bytes: 1760

On 6/15/2024 5:13 PM, HenHanna wrote:
> On 6/15/2024 2:30 PM, Paul Rubin wrote:
>> HenHanna <HenHanna@devnull.tb> writes:
>>> def diff1(x):
>>>      if len(x) <= 1: return True
>>>      for i in range(len(x) - 1):
>>>          if abs(x[i] - x[i+1]) != 1:    return False
>>>      return True
>>
>> def diff2(x):
>>    return all(abs(a-b)==1) for a,b in zip(x,x[1:]))
> 
> 
> Does this work when x is  []  or  [1]  ?


i'm pretty sure that  x[1:]  would  raise an error.


             Lispers can learn from Pythonicity and vice versa.