Re: [Tutor] faster substring replacement

2009-12-16 Thread Dave Angel
R. Alan Monroe wrote: I'm wondering whether text.replace has to shove oodles of text to the right in memory when you replace a shorter word with a longer word. Someone else on the list may know. Alan Since a string is immutable, replace() has to copy the string. So it doesn't need to

Re: [Tutor] faster substring replacement

2009-12-15 Thread R. Alan Monroe
> 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 so

Re: [Tutor] faster substring replacement

2009-12-15 Thread Kent Johnson
On Tue, Dec 15, 2009 at 12:19 PM, Luhmann wrote: > 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]) > ...

Re: [Tutor] faster substring replacement

2009-12-15 Thread Tim Golden
Luhmann wrote: 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

[Tutor] faster substring replacement

2009-12-15 Thread Luhmann
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