11/15


#1

how do you do this????


#2

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


#3

def count (sequence, item):
return sequence.count(item)


#4

@vanderblugen's reply is obviously the simplest way to do this, but as listed in the practice instructions, we should try and do this the hard(er) way, which is the code @cssslayer72984 posted:

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

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

#6

Why aren't you required to assign the "i" variable a value before the for loop?


#7

should you not be returning c instead of found as you don't define count before you returned it


#8

sorry i mean found instead of count


#9

@n3sky This confused me, too. I think it works because you later perform an operation on i within the for-loop (in this case, you test it with the "equals" operator against item).

You don't have to define or initialize i; the is the first time Python is seeing it, so it's expecting you do something with it later. If your for-loop didn't perform any operation with i, then you might have a problem.


#10

ya sorry , you are right