11/15 What's wrong in the code


num = [1,2,3,4,1,2,3,1,1]
rep = 1
def count(sequence, item):
result = 0
for i in num:
if rep == i:
result += 1
return result

print count(num,rep)


Sorry I had to withdraw my post I noticed an error in it.
Here's my code.

def count(sequence, item):
found = 0
for num in range(len(sequence)):
    if sequence[num] == item:
            found += 1
    sequence[num] == item
return found
print count([2,2,2], 2)


Have you had any luck with your code? You have the same thought process as I do. My code works fine as long as sequence doesn't include another list; however if it includes a list - it doesn't pick-up matches that are included there.


works with integer, float, another list, etc

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

    return total