I have a list1 containing different integers. Now, I want to create a second list (list2), that contains all elements of list1 without doubles. And I want to create list2 with list comprehension, without the need of defining it first as an empty list:
list1 = [3,3,2,1,5,6,1,5,7]
list2 = [i for i in list1 if i not in list2]
print(list2)
That case would be perfect for set(), I know. But why it is not working with a list comprehension?
In these threads I found, that my list2-syntax should be fine:
Both top voted answers suggest a syntax like
[y for y in a if y not in b]