Remove_duplicates error


#1



def remove_duplicates(llist):
newlist = []
templist = llist[:]
for i in templist:
if i not in newlist:
newlist.append(i)
templist.remove(i)

return newlist


Oops, try again. remove_duplicates([6, 8, 122, 2, 18]) returned [6, 122, 18] instead of [8, 122, 18, 2, 6]


Replace this line with your code.


#2

There is no need to remove elements from the main list, simply iterate over it. The new list will contain only unique characters.


#3

You dont need this,

templist.remove(i)

also you don't need tempelist!


#4

Thank You very much for your reply.It was very helpful.


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.