[Tutor] faster substring replacement
Luhmann
luhmann_br at yahoo.com
Tue Dec 15 18:19:27 CET 2009
Hi folks,
I'm trying to do something like this:
>>> evildict= {'good' : 'bad' , 'love' : 'hate' , 'God': 'Satan'}
>>> def make_evil(text)
... for a in evildict:
... text=text.replace(a, evildict[a])
... return text
This works fine, but it soon gets too slow as the size of text and dictionary begin to grow.
Can you guys suggest me a way to make it faster?
Devenez un meilleur amigo grâce à Yahoo! Courriel
http://cf.promos.yahoo.com/courriel/visiteguidee2/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091215/5f2006a3/attachment.htm>
More information about the Tutor
mailing list