[Python-ideas] in str.replace(old, new), allow 'old' to accept a tuple

Mark Lawrence breamoreboy at yahoo.co.uk
Fri Apr 13 05:43:40 CEST 2012

On 12/04/2012 03:46, Ben Finney wrote:

> And if they should be done in order, then that order should be explicit.
> I think the existing solution helps with that.

Something along the lines of

 >>> mystr = 'foo bar baz'
 >>> for old in 'foo', 'bar':
...     mystr = mystr.replace(old, 'baz')
 >>> mystr
'baz baz baz'

Or can this be simplified with the Python Swiss Army Knife aka the 
itertools module? :)


Mark Lawrence.

More information about the Python-ideas mailing list