if d.index(a)==0 or d.index(a)==-1:
d.remove(a)
else:
break
print(no)
Move the print
statement before the break
.
[edit]
Change the while loop to the following:
while len(d)!=0:
a=max(d)
print(F'max: {a}, index: {d.index(a)}')
if d.index(a)==0 or d.index(a)==len(d) - 1:
d.remove(a)
print(F'{a} removed')
else:
print('no')
break
print('yes: ', d)
Note: the added print statements show exactly what happens.
[/edit]