def last_replace(s, old, new, number_of_occurrences):
    """
    Replaces last n occurrences of the old string with the new one within the string provided

    :param s: string to replace occurrences with
    :param old: old string
    :param new: new string
    :param number_of_occurrences: how many occurrences should be replaced
    :return: string with last n occurrences replaced
    """
    list_of_components = s.rsplit(old, number_of_occurrences)
    return new.join(list_of_components)