[Python-ideas] string.replace should accept a list as a first argument
M.-A. Lemburg
mal at egenix.com
Tue Oct 6 18:34:16 CEST 2015
On 06.10.2015 21:25, Emil Rosendahl Petersen 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".
I think the "one obvious way" of doing a multi-replace is to
use the re module, since implementing this efficiently is
non-trivial.
String methods are meant to be basic (high performance)
operations.
--
Marc-Andre Lemburg
eGenix.com
Professional Python Services directly from the Source
>>> Python Projects, Coaching and Consulting ... http://www.egenix.com/
>>> mxODBC Plone/Zope Database Adapter ... http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
________________________________________________________________________
::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
http://www.egenix.com/company/contact/
More information about the Python-ideas
mailing list