The purify problem


#1

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

Can someone please help me of what is wrong here please?

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

I have tried filling some numbers in the array number list in the call function brackets but it still doesn’t work


def purify(lst):
    new_list = []
    for i in range(1, len(lst)+1):
        if i % 2 == 0:
            new_list.append(i)
    return new_list

print purify([])

#2

for i in range(1, len(lst)+1):

here what is i ?It loops from 1 to the length of the lst.
But it should be loop through the values of the lst.then you should check whether or not the number( i in for loop ) divided by two has a remainder of 0.


#3

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