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

Sven R. Kunze srkunze at mail.de
Tue Oct 6 19:47:30 CEST 2015


On 06.10.2015 18:37, Ryan Gonzalez wrote:
> 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

Yes, but(TM):

The OP has a list, not a string. Yes, he could create one by 
'|'.join(['undesirable', 'filthy']) but that's like:

"Hey, I have some structured data, let's create some applesauce and have 
a secondary parser re-create structured data from it." IMHO that feels 
wrong.

Best,
Sven


More information about the Python-ideas mailing list