[Python-ideas] string.swap()

Bruce Leban bruce at leapyear.org
Mon Apr 6 17:21:35 CEST 2009

On Mon, Apr 6, 2009 at 6:09 AM, Aahz <aahz at pythoncraft.com> wrote:

> On Mon, Apr 06, 2009, spir wrote:
> >
> > Some time ago on this list was mentionned swapping sub-strings inside
> > a string....
> >
> > * Sub-strings to be swapped must not be single characters.
> This seems like an odd requirement.  In any case, posting as a recipe
> seems the way to go.

I think the meaning of this was sub-strings must not be limited to single

There's a more general operation here that I've used on occasion:

        multiReplace(text, {"old value": "new value", "old2" : "new2", ...})

which replaces all the old values with the new values. In a sense this is a
generalized form of translate. Swap is a special case of this. In the case
of overlapping strings, the earliest match wins. If two strings share a
common prefix, then there needs to be a tiebreaking rule for that: shortest
or longest wins.

--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20090406/94f2b00b/attachment.html>

More information about the Python-ideas mailing list