[Python-ideas] str.rreplace
Amber Yust
amber.yust at gmail.com
Sat Jan 25 09:01:50 CET 2014
(Er, module the missing return keyword.)
On Sat Jan 25 2014 at 12:01:28 AM, Amber Yust <amber.yust at gmail.com> wrote:
> On Fri Jan 24 2014 at 11:55:57 PM, Georg Brandl <g.brandl at gmx.net> wrote:
>
> 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))
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140125/66099038/attachment.html>
More information about the Python-ideas
mailing list