1
I need to do a function that takes as input a string, a letter, and a number that indicates the desired occurrence of the letter (1 for first occurrence, 2 for second, etc).
The function needs to return where the string position is.
If there are fewer occurrences of the letter than the requested occurrence, the function must return -1.
Example: ("Mariana eats banana",'a',3). Answer: 6 (position of the third occurrence of the letter 'a' in the given string)
Trying:
def posLetra(string,letra,n):
i=0
indice=0
while i<len(string):
x=str.find(string,letra)
indice=indice+x
i=i+0
return indice