• please tell me what's wrong with my code.

Question related to mission Non-unique Elements

 
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.