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

Tshepang Lekhonkhobe tshepang at gmail.com
Wed Apr 11 22:35:54 CEST 2012


I find the fact that 'prefix' in str.startswith(prefix) accept a tuple
quite useful. That's because one can do a match on more than one
pattern at a time, without ugliness. Would it be a good idea to do the
same for str.replace(old, new)?

>>> 'foo bar baz'.replace('foo', 'baz').replace('bar', 'baz')
baz baz baz

>>> 'foo bar baz'.replace(('foo', 'bar'), 'baz')
baz baz baz

More information about the Python-ideas mailing list