I was trying to remove duplicates from a list using the following code:
a = [1,2,3,4,2,6,1,1,5,2]
res = []
[res.append(i) for i in a if i not in res]
But I would like to do this without defining the list I want as an empty list (i.e., omit the line res = []
) like:
a = [1,2,3,4,2,6,1,1,5,2]
# Either:
res = [i for i in a if i not in res]
# Or:
[i for i in a if i not in 'this list'] # This list is not a string. I meant it as the list being comprehended.
I want to avoid library imports and set()
.