I want to find the position (or index) of the last occurrence of a certain substring in given input string str.
str
For example, suppose the input string is
If you don't wanna use rfind then this will do the trick/
def find_last(s, t): last_pos = -1 while True: pos = s.find(t, last_pos + 1) if pos == -1: return last_pos else: last_pos = pos