I'm working on a Python exercise at Codecademy and got stuck on what looks like a simple problem:
Write a function
fizz_count()that loops through all the elements of a list. When the element is'fizz', increment a counter calledcount. Then return the value ofcount.
My code:
def fizz_count(x):
count = 0
for i in x:
if x[i] == 'fizz':
count = count + 1
return count
I get this error message:
An exception was raised for fizz_count(['fizz', 'buzz']): list indices must
be integers not str
Everything is formatted exactly as shown. I can't figure out where the error is.
iis a string. Why notprint ito find out why?