Reputation: 2190
I want to find how many times an character repeated in a word for example: how many times the 'l' repeated in the "Hello". but it drops me this error:
IndexError: string index out of range
And my code:
def fin(x,lst):
if x == '':
return 0
if lst[0] == x:
return 1+ fin(x,lst[1:])
else:
return fin(x,lst[1:])
Upvotes: 0
Views: 106
Reputation: 11691
There are pre-written functions in python to do this for you. But if you're doing this for the sake of education...
You have the wrong stop condition, you should be checking if the lst
is empty, not x
Upvotes: 4