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

Tshepang Lekhonkhobe tshepang at gmail.com
Thu Apr 12 11:39:45 CEST 2012


On Thu, Apr 12, 2012 at 06:37, Ben Finney <ben+python at benfinney.id.au> wrote:
> Cameron Simpson <cs at zip.com.au> writes:
>
>> "At the same time" might imply something equivalent to the cited
>> "re.sub('foo|bar',...)" suggestion. And that is different to an iterated
>> "replace foo, then replace bar" if the possible matched overlap.
>
> Yes, it is; but the OP presented a proposal as though it were to have
> the same semantics as a sequence of replace operations.
>
> If the OP wants to specify different semantics, let's hear it.

You guys are thinking more deeply about this than I was. I don't even
see a difference between the 2:

>>> 'foo bar baz'.replace('foo', 'baz').replace('bar', 'baz') == re.sub('foo|bar', 'baz', 'foo bar baz')
True

I was not even thinking about ordering, but it would help to have it
to avoid confusion I think. The example I gave was just the closest I
could think of.



More information about the Python-ideas mailing list