How to square only the positive numbers in a list?
<p>I am trying to only square the positive numbers in a list. But when I try the code it squares all of them</p>

<pre><code>def squarethis(numbers):
for n in numbers:
    if n &gt; 0:
        return[n ** 2 for n in numbers]

print(squarethis([1, 3, 5, -81]))
</code></pre>

<p>Why does it square all numbers? The if-statement should filter the negatives out right?</p>

<p>A purely functional alternative -></p>

<pre><code>&gt;&gt;&gt; map(lambda x: x**2, filter(lambda x: x &gt; 0, [1, 2, 3, -1, -2, -3]))
[1, 4, 9]
</code></pre>

python list math int square