how to remove the first occurence of an integer in a list
<p>this is my code:</p>

<pre><code>positions = []
for i in lines[2]:
    if i not in positions:
        positions.append(i)
print (positions)
print (lines[1])
print (lines[2])
</code></pre>

<p>the output is: </p>

<pre><code>['1', '2', '3', '4', '5']
['is', 'the', 'time', 'this', 'ends']
['1', '2', '3', '4', '1', '5']
</code></pre>

<p>I would want my output of the variable "positions" to be; ['2','3','4','1','5']
so instead of removing the second duplicate from the variable "lines[2]" it should remove the first duplicate.</p>

<p>you can use a dictionary to save the last position of the element and then build a new list with that information</p>

<pre><code>&gt;&gt;&gt; data=['1', '2', '3', '4', '1', '5']
&gt;&gt;&gt; temp={ e:i for i,e in enumerate(data) }
&gt;&gt;&gt; sorted(temp, key=lambda x:temp[x])
['2', '3', '4', '1', '5']
&gt;&gt;&gt; 
</code></pre>

python python-3.x