New course! Every coder should learn Generative AI!
Try a free lesson+ 1
Here you go, I only correct the syntax errors, you can check the logic
def accordian(l):
di=[]
res=[]
for x,y in list(zip(l[:],l[1:])):
d1=abs(y-x)
di.append(d1)
for i,j in zip(di[:],di[1:]):
if i<j:
flag=1
elif i==j:
flag=2
else:
flag=0
res.append(flag)
for s in res:
if s==2:
return False
return all(m!=n for m,n in zip(res,res[1:]))
print(accordian([1,2,3,4,5]))