12/15 Purify Help explain


In the following exercise my code is correct but i seem to always have an issue with the indentation. Where the answer is not displayed correctly on the console. For instance in the following code…

def purify(lis):
e = []
for l in lis:
if l % 2 == 0:
return e

print purify([2,4,4,4,5])

Only [2] will show up on the console, but when i move “return” to the left, the code functions perfectly, and all the even numbers are displayed on the console.

If someone could elaborate as to why this occurs i would really appreciate it.
thx in advance


If time it runs the return statement in the if statement so when it finds the first even number so you just get [2]

When you move it to the left the return statement runs after the for loop.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.