[Solved] Counting a specific string in the list in Python


You need to have the count variable inside for loop, and you dont require an else condition

def fizz_count(x):
    count=0
    for string in x:
        if string == 'fizz':
            count = count + 1
    return count

You can also write your function as

def fizz_count(x):
    return x.count('fizz')

solved Counting a specific string in the list in Python