Remove duplicates


#1



is this code wrong

def remove_duplicates(x):
    result = []
    for a in x:
        result.append(a)
        for i in range(a+1,len(x)):
            if a==i:
                result.remove(a)
    return result

#2

i think so

how about our list made of strings "text"


my idea ; copy x ( list ) to result , if item in x is duplicate remove it from result ..


#3

See my solution, in my opinion it seems to me more easy and clear:

def remove_duplicates(nums):
removed = []
for i in nums:
if i not in removed:
removed.append(i)
return removed


#4

also don't forget about identation


#5

def remove_duplicates(alist):
nlist = set(alist)
return nlist


#6

Nice, except it doesn't meet the requirement of using a loop structure :disappointed:


#7

The problem says not to modify the original list. Your code does just that.