Why is this condition-based list comprehension not working?
<p>I want to create a list from an existing list after removing all duplicates.
Program works if I use a "for loop" but nothing happens if I use a list comprehension.</p>

<pre><code>#use for loop
l=[1,2,2,3,1,1,2]
j=[]

for i in l:
    if i not in j:
        j.append(i)

print l
print j


#using list
l1=[1,2,2,3,1,1,2]
j1=[]

j1=[i for i in l1 if i not in j1]

print l1 
print j1
</code></pre>

<p><code>j1</code> is <code>[]</code> at the start and isn't updated at intermediate points within the list comprehension. Could do this instead of list comprehension though:</p>

<pre><code>l1=[1,2,2,3,1,1,2]
j1=list(set(l1))

print l1 
print j1
</code></pre>

python list python-2.7 list-comprehension