(Er, module the missing return keyword.)<br><br><div>On Sat Jan 25 2014 at 12:01:28 AM, Amber Yust <<a href="mailto:amber.yust@gmail.com">amber.yust@gmail.com</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>On Fri Jan 24 2014 at 11:55:57 PM, Georg Brandl <<a href="mailto:g.brandl@gmx.net" target="_blank">g.brandl@gmx.net</a>> wrote:</div><blockquote style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
There was also the suggestion on stackoverflow of<br>
<br>
'x'.join('aaa'.rsplit('aa', 1))<br>
<br>
which might be faster and less colon-y, but is very good at covering up the<br>
real purpose of the code :)<br></blockquote><div><br></div><div>Which is why you throw it in a clearly named function.</div><div><br></div><div>def rreplace(haystack, needle, replacement, count):</div><div> """Replace the N rightmost occurrences of one string with another."""</div>
<div> replacement.join(haystack.rsplit(needle, count)) </div></blockquote>