12. Purify


#1



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


I get the following error message:

Oops, try again. Your function crashed on [1] as input because your function throws a "'int' object is not iterable" error.


It gives me the correct answer but won't say complete


numbers = [1,2,3,4,5,6,7]
def purify(l):
    a=[]
    for i in range(len(l)):
        if i % 2 ==0:
            a.append(i)
    return len(a)
print purify([1,2,2,6,4,1,3])
print purify(numbers)


#2

Since we are not mutating the list, only scanning it, we can use a look up instead of a range.

for item in list:

When using a range, the iterator variable is the index, not the item.

for i in range(len(list)):
    if list[i] ...  : 
        a.append(list[i])

#7

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