11 Apr
2012
11 Apr
'12
5:41 p.m.
Tshepang Lekhonkhobe schrieb am Wed, 11. Apr 2012, um 22:35:54 +0200:
before
'foo bar baz'.replace('foo', 'baz').replace('bar', 'baz') baz baz baz
after
'foo bar baz'.replace(('foo', 'bar'), 'baz') baz baz baz
The usual current solution is to use `re.sub`: >>> re.sub("foo|bar", "baz", "foo bar baz") 'baz baz baz' or, for a general iterable of patterns re.sub("|".join(map(re.escape, patterns)), repl, string) Cheers, Sven