Python 2 vs Python 3 - Difference in behavior of filter : <p>Could someone please help me understand why the following code that implements the "sieve of Eratosthenes" behaves differently across Python 2 and Python 3.</p>

<pre><code>l = range(2, 20)
for i in range(2, 6):
    l = filter(lambda x: x == i or x % i != 0, l)
print(tuple(l))
</code></pre>

<p>With Python 2.7:</p>

<pre><code>&gt; python filter.py
(2, 3, 5, 7, 11, 13, 17, 19)
</code></pre>

<p>with Python 3.6:</p>

<pre><code>&gt; python filter.py
(2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19)
</code></pre>

<p>I understand that Python3's filter returns a filter object but can't explain the final result. (The code is from this lambdas tutorial <a href="http://www.secnetix.de/olli/Python/lambda_functions.hawk" rel="noreferrer">1</a>).</p>
