Re: diff1(x) in Python: True if all adjacent items differ by 1, False otherwise.

Liste des GroupesRevenir à cl lisp 
Sujet : Re: diff1(x) in Python: True if all adjacent items differ by 1, False otherwise.
De : michael.stemper (at) *nospam* gmail.com (Michael F. Stemper)
Groupes : comp.lang.python comp.lang.lisp
Date : 17. Jun 2024, 15:11:23
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4pclr$luk9$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 15/06/2024 19.13, 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]  ?
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.

Date Sujet#  Auteur
15 Jun 24 * diff1(x) in Python: True if all adjacent items differ by 1, False otherwise.8HenHanna
15 Jun 24 `* Re: diff1(x) in Python: True if all adjacent items differ by 1, False otherwise.7Paul Rubin
16 Jun 24  `* Re: diff1(x) in Python: True if all adjacent items differ by 1, False otherwise.6HenHanna
16 Jun 24   +- Re: diff1(x) in Python: True if all adjacent items differ by 1, False otherwise.1Kaz Kylheku
16 Jun 24   +* Re: diff1(x) in Python: True if all adjacent items differ by 1, False otherwise.3HenHanna
16 Jun 24   i+- Re: diff1(x) in Python: True if all adjacent items (Posting On Python-List Prohibited)1Lawrence D'Oliveiro
16 Jun 24   i`- Re: diff1(x) in Python: True if all adjacent items differ by 1, False otherwise.1HenHanna
17 Jun 24   `- Re: diff1(x) in Python: True if all adjacent items differ by 1, False otherwise.1Michael F. Stemper

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal