I am working my way through the Think Python Textbook, and one of the problems it gives is to make a function that takes a list and returns a list with only unique elements from the original. What I have so far is this:
def remove_duplicates(l):
index = 0
new_l = []
dup_l = []
while index < len(l):
if l[index] in l[index+1:] or l[index] in new_l:
dup_l += [l[index]]
index = index + 1
elif l[index] in dup_l:
index = index + 1
else:
new_l += [l[index]]
return new_l
I feel like there must be a more succinct, pythonic way to write this function. Can somebody help this beginner programmer?