25 Jan
2014
25 Jan
'14
8:01 a.m.
On Fri Jan 24 2014 at 11:55:57 PM, Georg Brandl
There was also the suggestion on stackoverflow of
'x'.join('aaa'.rsplit('aa', 1))
which might be faster and less colon-y, but is very good at covering up the real purpose of the code :)
Which is why you throw it in a clearly named function. def rreplace(haystack, needle, replacement, count): """Replace the N rightmost occurrences of one string with another.""" replacement.join(haystack.rsplit(needle, count))