Lists + Functions


#1

def fizz_count(x):
    count=0
    for item in x:
        if x == "fizz":
            count=count+1
    return count
small=["fizz","buzz"]
fizz_count(small)
print fizz_count(small)

Is there anything wrong in this code?This does not work.


#2

does not work...................


#3

this line:

if x == "fizz":

x is the list, that will never equal a string fizz. You should compare item with fizz, item will hold the items inside the loops in turn thanks to your for loop


#4

yep,It worked.Thank you very much.