Remove duplicates


is this code wrong

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


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 ..


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:
return removed


also don't forget about identation


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


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


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