12. purify call function


Can someone please tell me ho do i call this function?
The code is correct but i dont know how to call it. Thanks!

def purify(numbers):
new_number = []
for n in numbers:
if n%2 == 0:
return new_number


You can use the following statement:
It worked for me.


I think you need "else: continue"

if n % 2 == 0:


I don't think else statement is needed for this as it only requires you to send one list

I came up with this:

def purify(uInput):
    even = []
    for i in uInput:
        if (i % 2 == 0):
    return even
print purify([1,2,3])

And function can be called the way I've called print purify([1,2,3]) with user input added into the function parameter as a list.


thanks Mohammed..nice code here :grin:


Here's how I did it.

def purify(sequence):
sequence = list(sequence)
result = []
for i in sequence:
if i % 2 == 0:
return result


Hey Mohammed7690,

First, thank you for saving my sanity.

I was scrubbing your code against my old iterations... and found that I had the same idea... a couple times.. :expressionless:

But, here's the kicker I was trying to store my output in another variable because I didn't know you could just append without storing the data... well, in a for loop anyway...

Two questions:

  1. Do you need the parenthesis in your if statement?
  2. Why does this not work:
    def purify(list_of_numbers)
    even = []
    for i in list_of_numbers:
    if i % 2 == 0:
    even = even.append(i)
    return even

Thanks a bunch,

PS the indents are there when I edit?


def purify(numbers):
return filter(lambda x : x % 2 == 0, numbers)