Re: Double replace or single re.sub?

2005-10-27 Thread EP
How does Python execute something like the following oldPhrase=My dog has fleas on his knees newPhrase=oldPhrase.replace(fleas, wrinkles).replace(knees,face) Does it do two iterations of the replace method on the initial and then an intermediate string (my guess) -- or does it compile to

Re: Double replace or single re.sub?

2005-10-27 Thread Bengt Richter
On 27 Oct 2005 12:39:18 -0700, EP [EMAIL PROTECTED] wrote: How does Python execute something like the following oldPhrase=My dog has fleas on his knees newPhrase=oldPhrase.replace(fleas, wrinkles).replace(knees,face) Does it do two iterations of the replace method on the initial and then an

Re: Double replace or single re.sub?

2005-10-27 Thread Alex Martelli
Iain King [EMAIL PROTECTED] wrote: I have some code that converts html into xhtml. For example, convert all i tags into em. Right now I need to do to string.replace calls for every tag: html = html.replace('i','em') html = html.replace('/i','/em') I can change this to a single call to

Double replace or single re.sub?

2005-10-26 Thread Iain King
I have some code that converts html into xhtml. For example, convert all i tags into em. Right now I need to do to string.replace calls for every tag: html = html.replace('i','em') html = html.replace('/i','/em') I can change this to a single call to re.sub: html = re.sub('([/]*)i', r'\1em',

Re: Double replace or single re.sub?

2005-10-26 Thread Mike Meyer
Iain King [EMAIL PROTECTED] writes: I have some code that converts html into xhtml. For example, convert all i tags into em. Right now I need to do to string.replace calls for every tag: html = html.replace('i','em') html = html.replace('/i','/em') I can change this to a single call to

Re: Double replace or single re.sub?

2005-10-26 Thread Iain King
Mike Meyer wrote: Iain King [EMAIL PROTECTED] writes: I have some code that converts html into xhtml. For example, convert all i tags into em. Right now I need to do to string.replace calls for every tag: html = html.replace('i','em') html = html.replace('/i','/em') I can

Re: Double replace or single re.sub?

2005-10-26 Thread SPE - Stani's Python Editor
Of course it is better to precompile the expression, but I guess replace will beat even a precompiled regular expression. You could see this posting: http://groups.google.nl/group/comp.lang.python/msg/32af24eab9024f60?hl=nlq=replace+re+speed+python+sub But performance should be measured, not

Re: Double replace or single re.sub?

2005-10-26 Thread Josef Meile
Hi Iain, Would this be a quicker/better way of doing it? I don't know if this is faster, but it is for sure more elegant: http://groups.google.ch/group/comp.lang.python/msg/67b8767c793fb8b0 I really like it because of its simplicity an easy use. (Thanks to Fredrik Lundh for the script).