Sujet : Re: diff1(x) in Python: True if all adjacent items differ by 1, False otherwise.
De : no.email (at) *nospam* nospam.invalid (Paul Rubin)
Groupes : comp.lang.python comp.lang.lispDate : 15. Jun 2024, 22:30:56
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <8734pd7v1r.fsf@nightsong.com>
References : 1
User-Agent : Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
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:]))