I tried to create a simple function to remove duplicates from the list.
x = [7, 7, 5, 6, 8, 9, 9, 0]
for n, i in enumerate(x):
if i in x[n + 1:]:
x.remove(i)
print(x)
Output:
[7, 5, 6, 8, 9, 0]
This code works fine as far as I know.
But when I'm trying to convert it in comprehension list form, I'm getting wrong output:
def unique_list(lst):
return [lst.remove(i) for n, i in enumerate(lst) if i in lst[n + 1:]]
x = [7, 7, 5, 6, 8, 9, 9, 0]
print(unique_list(x))
Output:
[None, None]
So, the question is - why the output is different?