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
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
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
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',
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
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
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
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).