[Python-ideas] str.rreplace
Chris Angelico
rosuav at gmail.com
Sat Jan 25 08:37:58 CET 2014
On Sat, Jan 25, 2014 at 6:16 PM, Serhiy Storchaka <storchaka at gmail.com> wrote:
> 24.01.14 23:04, MRAB написав(ла):
>
>> On 2014-01-24 20:48, Chris Angelico wrote:
>>>
>>> On Sat, Jan 25, 2014 at 7:33 AM,
>>> <random832 at fastmail.us> wrote:
>>>>>>>
>>>>>>> 'aaa'[::-1].replace('aa'[::-1],'x'[::-1])[::-1]
>>>>
>>>> 'ax'
>>>
>>>
>>> It makes me happy when the [::-1] smiley gets used that many times to
>>> solve a problem. Very happy.
>>>
>>> Happy that it isn't in _my_ code, to be precise...
>>>
>> It's probably not as efficient, either!
>
>
> Of course it is less efficient than hypothetical rreplace, but I suppose it
> is most efficient way in current Python.
Is it possible to use a reversed iterator, filter it through something
that does the replacement, and then do some sort of reversed ''.join()
at the end? It'd still be ugly though.
ChrisA
More information about the Python-ideas
mailing list