def find_nth(haystack, needle, n):
    start = haystack.find(needle)
while start >= 0 and n > 1:
    start = haystack.find(needle, start + len(needle))
n -= 1
return start
Find the nth occurrence of substring in a string