For loop not going over each element in a list


Hello, I'm having a bit of trouble with this for loop. I'm fairly sure its just a simple mistake I'm glossing over, but I'd appriciate some help in any case.

The error message I'm receiving is:

Oops, try again. Your function fails on purify([4, 5, 5, 4]). It returns [4] when it should return [4, 4].

The code I'm running doesn't seem to be "seeing" each element on the list. It finds the first number that is even, appends it to the list, and then stops.

def purify(numbers):
    new = []
    for c in numbers:
        if c % 2 == 0 and c != 0:
        return new


as soon as a return keyword is reached, the function ends. In your case, in the first run of the for loop, a return keyword is reached, which means the loop and function ends.

You might want to reconsider where to put your return, if you need further help, let me know (post a reply with your updated code)


Thanks so much! I Can't believe it was as easy as moving the "return". Code works fine now.


no problem, you could also just remove else altogether. It isn't doing anythign