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

Stephen J. Turnbull stephen at xemacs.org
Fri Apr 13 05:14:51 CEST 2012

On Fri, Apr 13, 2012 at 11:03 AM, Raymond Hettinger
<raymond.hettinger at gmail.com> wrote:

> What I have needed and have seen others need is a dictionary
> based replace:     {'customer': 'client', 'headquarters': 'office', 'now':
> 'soon'}.
> Even that case is a fraught with peril -- I would want "now" to change
> to "soon" but not have "snow" change to "ssoon".
> In the end, I think want people want is to have the power
> and control afforded by re.sub() but without having
> to learn regular expressions.

There is one very attractive special case, however, which is an
invertible translation like URL-escaping (or HTML-escaping), where at
least one side of the transform is single characters.  Then there is
no ambiguity.  Nevertheless, I think that case is special enough that
it may as well be done in the modules that deal with URLs and HTML

More information about the Python-ideas mailing list