Это именно то, для чего используется функция rpartition
:
rpartition (...)
S.rpartition (сеп) -> (голова, сеп, хвост)
Search for the separator sep in S, starting at the end of S, and return
the part before it, the separator itself, and the part after it. If the
separator is not found, return two empty strings and S.
Я написал эту функцию, показывающую, как использовать rpartition
в вашем случае:
def replace_last(source_string, replace_what, replace_with):
head, _sep, tail = source_string.rpartition(replace_what)
return head + replace_with + tail
s = "123123"
r = replace_last(s, '2', 'x')
print r
Выход:
1231x3