Purify Error


#1

Purify Error

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

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:
            purified.append([num])
    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]]
None

What's the issue?


#2

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


#3

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