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

Emil Rosendahl Petersen emilrosendahlpetersen at outlook.com
Tue Oct 6 21:25:00 CEST 2015


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



More information about the Python-ideas mailing list