Generator Error - not printing list returned in function from generator


#1



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


Hi, i'm getting an error when I return the "new_lst" using this generator function.

Typically if I wrapped the function output in a 'print' or print( list( purify( [1,2,3] ) ) I get the resulting list to print out but it is not working this time. Any suggestions?

Error: generator object purify at 0x104a05990>


def purify(lst):    
    new_lst = []
    return (new_lst.append(num) for num in lst if num % 2 == 0)

purify((1,2,3))


#2

if you want to do this, use list comprehension, not a generator expression


#3

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