Help me to execute this! i unable to find the error in this


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

This is my code 
   def purify(n):
    for i in n:
        if i % 2 != 0:
    return n


remove causes index shifts, which mean a second successive odd number gets skipped

try the opposite approach: append constants to a new list


which is the opposite approach here? didnt get you!


append the even numbers to a new list


Yes.. I did ..But again it showing errors.like below,

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

my code is here:
def purify(n):
list = []
for i in n:
if i % 2 == 0:
return n


your return n, which is the original list. You should return the list to which you appended the even numbers


oh yes..thats my mistake..i didnt notice that.. Thank you


 def purify(n):
    for i in n:
        if i % 2 != 0:
    return n

This is your code ,lets see what your code does.
1. Your function purify takes a list.
2. It loops through each item of your list.
3. It checks if item is odd or not.
4. If it is odd then it removes item from list.
Now lets read what question is asking--

Define an empty list.
And as it says not to change original list, leave the old list.
What you do now?
You check for even numbers and append them in new list ?
The last part tho (The returning) ,I'm leaving upto you.
I hope it helps! :slight_smile:


the problem is already solved?


:grinning: When I finished my answer I saw It has been answered(and probably solved)! :thumbsup:


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