To jest dokładnie to, co funkcja rpartition
służy do:
rpartition (...) S.rpartition (SEP) -> (głowa, wrzesień, ogon)
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.
Napisałem tę funkcję, pokazujący jak używać rpartition
w przypadku użycia:
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
wyjściowe:
1231x3
Bardzo przepraszam, ja tylko edytowany moje pytanie, uczynienia go bardziej zrozumiałym. – Freewind
dziękuję ci wszystkim :) – Freewind