Python List and remove a variable
<p>I am new to programming. I was trying to understand different data structure in python. In List i was trying:</p>

<pre><code>mylist = [1,2,1,2,1,2,3,4,5,1,2,3]
print mylist
mylist.remove(2)
print mylist
</code></pre>

<p>It is supposed to remove 2 from the list. It does but the first one only.
The output is like:</p>

<pre><code>[1, 2, 1, 2, 1, 2, 3, 4, 5, 1, 2, 3]
[1, 1, 2, 1, 2, 3, 4, 5, 1, 2, 3]
</code></pre>

<p>How can i remove all the match ?</p>

<p><a href="https://docs.python.org/3.5/tutorial/datastructures.html" rel="nofollow">According to docs</a>, this behavior is expected:</p>

<blockquote>
  <p><code>list.remove(x)</code></p>
  
  <p><strong>Remove the first item from the list whose value is x</strong>. It is an error if there is no such item.</p>
</blockquote>

<p>To remove all occurences of value from list you may use list comprehension:</p>

<pre><code>seq = [1,2,1,2,1,2,3,4,5,1,2,3]
seq = [value for value in seq in value != 2]
</code></pre>

python python-2.7