Oops, try again. Your function fails on count([4, 'foo', 'foo'],5). It returns 1 when it should return 0.

The function returns 0 when tested.. not 1.

def count(sequence, item):
    found = 0
    while item in sequence:
        found += 1
    return found
print count([4, 'foo', 'foo'], 5)


Hi, @ronberko3 ,

This alters the original list ...


Instead of removing elements from the list, check for each element in the list whether it is equivalent to item. If it is, then increment count, without removing the element.


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