[Python-ideas] string.replace should accept a list as a first argument

Ryan Gonzalez rymg19 at gmail.com
Tue Oct 6 18:37:20 CEST 2015


import re

result = re.sub('undesirable|filthy', '', 'There are a lot of undesirable
people in this filthy world')
print(result) # There are a lot of people in this world


On Tue, Oct 6, 2015 at 2:25 PM, Emil Rosendahl Petersen <
emilrosendahlpetersen at outlook.com> wrote:

> I think string.replace should be changed accept a list as a first
> argument.
>
> That way, if I had this string:
>
> "There are a lot of undesirable people in this filthy world"
>
> Then I could do this, replace(['undesirable', 'filthy'], ''), in case
> that's what I wanted to do.
>
> Now, string.replace doesn't accept a list as its first argument, and
> complains about implicit conversion.
>
> Is there any great obstacle to just having the function loop over that
> list, calling itself in case we get a list argument instead of a str?
>
> Doesn't that seem like the more obvious behaviour? To me the results of
> running the above code should be unsurprising, if this change was
> implemented: "there are a lot of people in this world".
>
> / Emil Petersen
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
Ryan
[ERROR]: Your autotools build scripts are 200 lines longer than your
program. Something’s wrong.
http://kirbyfan64.github.io/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151006/2a8eff0d/attachment-0001.html>


More information about the Python-ideas mailing list