Path: ...!feeds.phibee-telecom.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Michael F. Stemper" Newsgroups: comp.lang.python,comp.lang.lisp Subject: Re: diff1(x) in Python: True if all adjacent items differ by 1, False otherwise. Date: Mon, 17 Jun 2024 08:11:23 -0500 Organization: A noiseless patient Spider Lines: 22 Message-ID: References: <8734pd7v1r.fsf@nightsong.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Mon, 17 Jun 2024 15:11:23 +0200 (CEST) Injection-Info: dont-email.me; posting-host="1a2a224911541de666da65aa8cf9c072"; logging-data="719497"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19w0eAS3vEj3jjw8rza7ZSARsb5wlDe1sA=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Cancel-Lock: sha1:uzCWUhu1rtQ5ChSUNd0uAMYMvdE= In-Reply-To: Content-Language: en-US Bytes: 1863 On 15/06/2024 19.13, HenHanna wrote: > On 6/15/2024 2:30 PM, Paul Rubin wrote: >> HenHanna 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]  ? The easiest way to find out would be to type it in to REPL and give it a whirl. -- Michael F. Stemper 87.3% of all statistics are made up by the person giving them.