rreplace - How to replace the last occurence of an expression in a string
- by Barthelemy
Is there a quick way in Python to replace strings by starting from the end? For example:
>>> def rreplace(old, new, occurence)
>>> ... # Code to replace the last occurences of old by new
>>> '<div><div>Hello</div></div>'.rreplace('</div>','</bad>',1)
>>> '<div><div>Hello</div></bad>'