lst = [1,2,90,2,1,9,3,9,6]
def checkio(data):
slst = sorted(data)
print(slst)
newlist = []
if slst[0] == slst[1]:
newlist.append(slst[0])
for i in range(1,len(slst)-1):
if slst[i] == slst[i+1] or slst[i-1]:
newlist.append(slst[i])
if slst[len(slst)-1] == slst[len(slst)-2]:
newlist.append(slst[len(slst)-1])
data = newlist
return data
print(checkio(lst))
the output is:
[1, 1, 2, 2, 3, 6, 9, 9, 90]
[1, 1, 2, 2, 3, 6, 9, 9]
i can't understand why the code is appending the '3' and the '6' even though they are not equal to their respective previous or subsequent terms.
can anyone tell me why this is?
thanks.
Created at: 2016/01/03 15:45; Updated at: 2016/01/05 20:26