Confused re: Purify


#1



https://www.codecademy.com/en/courses/python-intermediate-en-rCQKw/2/2?curriculum_id=4f89dab3d788890003000096#

i get the following error message:
'Your function fails on purify([4, 5, 5, 4]). It returns [] when it should return [4, 4].'

Confused because it looks like it will remove just the odd numbers.


def purify(lest):

    lest=[]
    
    for i in range(len(lest)):
        if i % 2 != 0 :
            lest.remove(i)
    return lest


#2

That line is wiping out the parameter value and should be removed.


#3

When I remove that line, I get the following error:

Your code looks a bit off--it threw a "list.remove(x): x not in list" error. Check the Hint if you need help!


#5

got it, that makes sense. thanks!


#6

This exercise is more about learning to do things step by step as opposed to reaching for a built-in function. Not that it's wrong to use the best tool at hand, but it should wait until we know the step by step approaches and understand them well enough to appreciate what the built in function is doing.

Can you find a way to do this lesson without using remove?


#7

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