Purify Error


Purify Error


My code is returning the following error
Oops, try again. Your function fails on purify([1]). It returns [] when it should return [].

I expected the code to be correct as it is returning what it should. I believe the error may be with my brackets [].

def purify(numbers):
    purified = []
    for num in numbers:
        if num % 2 == 0:
    return str(purified[0:])

print purify([1,2,3,4,5,6,7,8,9,2,4,6])

The output from the above is:
[[2], [4], [6], [8], [2], [4], [6]]

What's the issue?


why append [num] to purified? Just appending num is enough, no need to append a list to the purified list

also, you can just return purified as list, no need for slicing or string conversion


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