def fizz_count(x): counter = 0 for count in x: if ("fizz" in count) and type(count) != int: counter = counter + 1 return counter z = ["fizz","buzz","fizz"] print fizz_count(z)
Подскажите пожалуйста, почему крешится, если в список добавить числа?
def fizz_count(x): counter = 0 for count in x: if ("fizz" in count) and type(count) != int: counter = counter + 1 return counter z = ["fizz","buzz","fizz"] print fizz_count(z)
"fizz" in count
"fizz" in 23
"fizz" == count
FishHook
тогда ошибки не будет,
а вообще код плохой.
def fizz_count(x): return len([s for s in x if "fizz" in str(s)]) z = ["fizz", "buzz", "fizz", 1, 23, "fizzizz"] print fizz_count(z)
>>> z = ["fizz","buzz","fizz"] >>> z.count("fizz") 0: 2