Purify Error


#1


Can anyone help identify why this code doesn't work? I have seen the .append alternative but I want to know why this breaks down. Thanks

Oops, try again. Does your purify function take exactly one argument (a list of numbers)? Your code threw a "'int' object is not iterable" error.


    my_lst = [1,2,3,4,5,6,7]

    def purify(lst):
        new_lst = []
        for i in lst:
            if i % 2 == 0:
                new_lst += lst[i]
        return new_lst
        
    print purify(my_lst)

#2

There's your Achilles heel. We cannot use assignment when adding elements. Use LIST.append(), instead.


#3

hmm Interesting.

Thanks for this. On to the next!