在 Python 中有没有一种快速的方法来替换字符串,而不是像 replace
那样从头开始,从尾开始?例如:
>>> 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>'