def replace_last(source_string, replace_what, replace_with):
    """ Function that replaces the last ocurrence of a string in a word

        :param source_string: the source string
        :type source_string: str
        :param replace_what: the substring to be replaced
        :type replace_what: str
        :param replace_with: the string to be inserted
        :type replace_with: str
        :returns: string with the replacement
        :rtype: str

        :Example:

        >>> import chana.lemmatizer
        >>> chana.lemmatizer.replace_last('piati','ti','ra')
        'piara'
        
    """
    head, _sep, tail = source_string.rpartition(replace_what)
    return head + replace_with + tail