.remove() in Python list breaks a for loop
<p>I wrote a <code>for</code> loop that supposedly removes any elements that fits the description.</p>

<p>Example:</p>

<pre><code>for tag in tags:
    if tag.lower() in ['ex1', 'ex2', 'ex3']:
        tags.remove(tag)
</code></pre>

<p>My <code>tags</code> would look like <code>['EX1', 'EX2', 'ex1', 'ex2', 'ex3', 'ex4', 'ex5']</code> and I expect to keep only <code>ex4</code> and <code>ex5</code></p>

<p>What I noticed is that the for loop would skip some elements, giving me results like <code>['EX2', 'ex2', 'ex4', 'ex5']</code></p>

<p>I suspect this being indexing issue, but I'm not sure if that's really the case.</p>

<p>I ended up using a list comprehension, which does the job correctly, but I just want to understand the true reason behind the unexpected behavior.</p>