Count error


#1



Count


I get an error message saying that it takes too long for my code to return a result and to check for an infinite loop. When I run this outside of the codecademy site it works fine. What am I doing wrong?


Should return a count of the specified integer (item) found within a given list (sequence).


def count(sequence,item):
    i = 0
    found = 0
    while i <= len(sequence):
        if item in sequence:
            found += 1
            i += 1
            sequence.remove(item)
    return found


#2

Make a change to the code.....

Change

into

while i < len(sequence):

#3

Thanks, but I still get the same error with that change.


#4

Use the following code

sequence = [0,1,2]
print len(sequence)
sequence.remove(0)
print len(sequence)

)
and you will know
that removei-ing an item from the squence
will change its len-ght


#5

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