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


I'm not sure why, it's probably something really simple but i can't see it. Any help would be greatly appreciated :stuck_out_tongue:

def count(sequence, item):
    found  = 0
    for i in range(len(sequence)):
        if i == item:
            found += 1
            found += 0
    return found.


because you use range() you get indexes, which means you either need to use the index to access the items of the list:

if sequence[i] == item

or you can use a for in loop without range, this will give you the items in the list directly:

for i in sequence:


Yeah, figured that out just after i'd posted this :smile
Thanks anyway :thumbsup: