Có một cách nhanh chóng trong Python để thay thế các chuỗi nhưng, thay vì bắt đầu từ đầu như replace
vậy, bắt đầu từ cuối? Ví dụ:
>>> def rreplace(old, new, occurrence)
>>> ... # Code to replace the last occurrences of old by new
>>> '<div><div>Hello</div></div>'.rreplace('</div>','</bad>',1)
>>> '<div><div>Hello</div></bad>'