import re


def replacenth(string, sub, wanted, n):
    """Replace nth word in a sentence
    
    string: Complete string
    sub: Substring to be replaced
    wanted: Replace by wanted
    n: index of the occurence of sub to be replaced
    """
    where = [m.start() for m in re.finditer(sub, string)][n-1]
    before = string[:where]
    after = string[where:]
    after = after.replace(sub, wanted, 1)
    newString = before + after
    return newString