Why are certain elements of this python list ignored?
<p>I'm new to Python, and i'm struggling to understand the output of this simple program:</p>

<pre><code>list = os.listdir(os.getcwd())
print(list)
print()
for element in list:
    print(element)
    if 'txt' not in element: list.remove(element)
</code></pre>

<p>Which gives me this output :</p>

<pre><code>['examples_list.txt', 'generate_patterns.py', 'lehoczky_example_3.txt', 'patterns', 'test.py', 'test2.py']

examples_list.txt
generate_patterns.py
patterns
test2.py
</code></pre>

<p>why are certain elements (such as 'lehoczky_example_3.txt'), ignored by the "for" loop?</p>
