Sujet : Re: diff1(x) in Python: True if all adjacent items differ by 1, False otherwise.
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.python comp.lang.lispDate : 16. Jun 2024, 01:34:33
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240615173407.24@kylheku.com>
References : 1 2 3
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-06-16, HenHanna <
HenHanna@devnull.tb> 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] ?
Can we keep this abject filth out of the Lisp newsgroup?
Thanks. :)