Can't purify


It says: Your function fails on purify([4, 5, 5, 4]). It returns [4, 5, 4] when it should return [4, 4].

how come it doesn't remove the second 5?

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


Owing that a list is not a value, but a reference object we cannot copy by direct assignment. To copy a list to an independent variable use the List.copy() method; or you can use a list slice, n = numbers[:].

Iterate over the orginal list, numbers, afterward, and remove.from the copy in the loop. That should work.


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