mutliple search and replace

Trung Hoang thoa0025 at mail.usyd.edu.au
Thu Mar 28 17:02:14 EST 2002


hey Gustavo,

actually i wished to do the replacement in one sweep and occuring in any
order.. to avoid problems.. is it easy?

cheers


"Gustavo Cordova" <gcordova at hebmex.com> wrote in message
news:mailman.1017263863.2060.python-list at python.org...
> >
> > Greetings,
> >
> > Suppose i have a map (or two lists). is it possible to make a
> > sweep through
> > a string to find all occurances of key's in the map then
> > replace them all in
> > one sweep?
> >
> > cheers
> > trung
> >
>
> Sure, only that there's not a builtin function that does that,
> but it sounds easy enough to make it:
>
> def ReplaceLots(String, RDict):
>     "Replace all occurrences of all keys in RDict inside String"
>     for k in RDict:
>         String = String.replace(k, RDict[k])
>     return String
>
> Simple, eh? Yeah, that's Python for ya. :-)
>
> -gustavo
>





More information about the Python-list mailing list