Count exercise--are my variables all correct?


I'm not quite understanding the issue in this code. It returns the error message: "Oops, try again. Your function fails on count([4, 'foo', 5, 'foo'],5). It returns 0 when it should return 1."

Any help is appreciated.

This is the exercise for reference:

def count(sequence, item):
    found = 0
    for item in sequence:
        if found == item:
            found += sequence[item]
            return count
            return 0


I don't understand what you're trying to do.

Even if it functioned properly it would return 0 no matter what.


Of course. I see what I did wrong and have managed to fix and pass this.


Here is what I did:

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