6/11 count


#1

Not sure what I did wrong here. I get this error message "Your function fails on count([4, 'foo', 5, 'foo'],5). It returns 0 when it should return 1." Little help, please.

def count(sequence, item):
    seq = str(sequence)
    alist = seq.split()
    item = str(item)
    found = 0
    for x in alist:
        if x == item:
            found += 1
    return found

#2

I know there are other ways to do this using other functions, yet I am trying to figure out why this isn't working.


#3

Use the count([4, 'foo', 5, 'foo'],5) as the example. Add print statements to see why when using this statement to call the function that it doesn't work. Hopefully that'll give you some ideas.