I am new to python and I am trying to implement rfind function using find.
def rfind_imp(s,t):
ss = s
fpos = 0
while(True):
fpos = s.find(t,fpos)
ss=ss[fpos:]
if(ss):
fpos = fpos +1
else:
return fpos
print rfind_imp("I saw a donkey,I saw a saw "," ")
print "I saw a donkey,I saw a saw ".rfind(" ")
But the issue I am facing is I am getting 16th charcter as rfind value. Can some one help me find where I am doing a mistake. Also any suggestions for better implementation of rfind using find should be helpful.
I think your algorithm should be implemented like this:
Another algorithm that’s probably faster for strings with many ocurrences of
t:(Edit: made it work for strings with more than one character)