remove_duplicates why is it wrong!?


#1

I'm c++-programmer so I've write this one
and have checked with this http://www.pythontutor.com/visualize.html (python 2.7)
and it works perfect, but I can not pass this task with my code and I've seen much more better and shorter code
I want to know what is wrong here? Maybe somebody has the same trouble=)

def remove_duplicates(lst):
res = []
lst.sort()
if lst:
res.append(lst[0])
for t in lst:
if res[-1] != t:
res.append(t)
return res

"""print remove_duplicates([2,1,2,3,1,2,3])"""


#2

it's work now)
def remove_duplicates(lst):
res = []
lst_new = sorted(lst) <------------------------------------------------- you're need sort and save changes)
if lst:
res.append(lst_new[0])
for t in lst_new:
if res[-1] != t:
res.append(t)
return res