Re: trouble with replace

2006-08-13 Thread Anthra Norell
This might well take the trouble out ot the OP's replace: http://cheeseshop.python.org/pypi/SE/2.2%20beta Regards Frederic -- And here is how it works: >>> text = '''defgefabcdefy effwerbyuuuterrfr''' >>> im

Re: trouble with replace

2006-08-12 Thread Tim Chase
pats = ['abcdef', 'defgef', 'effwer'] reps = ['highway', 'news', 'monitor'] s = 'defgefabcdefy\n\n\n effwerbyuuuterrfr' reduce(lambda x,y: x.replace(*y), zip(pats,reps), s) The reduce() method fairly works well if you have it as a dictionary as well: >>> m = {'effwer':

Re: trouble with replace

2006-08-12 Thread Jason Nordwick
>>> pats = ['abcdef', 'defgef', 'effwer'] >>> reps = ['highway', 'news', 'monitor'] >>> s = 'defgefabcdefy\n\n\n effwerbyuuuterrfr' >>> reduce(lambda x,y: x.replace(*y), zip(pats,reps), s) 'newshighwayy\n\n\n monitorbyuuuterrfr' f pemberton wrote: > I have a string (xdata) and theres a

Re: trouble with replace

2006-08-12 Thread Simon Forman
Simon Forman wrote: > f pemberton wrote: > > Marc 'BlackJack' Rintsch wrote: > > > In <[EMAIL PROTECTED]>, f pemberton > > > wrote: > > > > > > > I've tried using replace but its not working for me. > > > > xdata.replace('abcdef', 'highway') > > > > xdata.replace('defgef', 'news') > > > > xdata.re

Re: trouble with replace

2006-08-12 Thread Simon Forman
f pemberton wrote: > Marc 'BlackJack' Rintsch wrote: > > In <[EMAIL PROTECTED]>, f pemberton > > wrote: > > > > > I've tried using replace but its not working for me. > > > xdata.replace('abcdef', 'highway') > > > xdata.replace('defgef', 'news') > > > xdata.replace('effwer', 'monitor') > > > > `rep

Re: trouble with replace

2006-08-12 Thread f pemberton
Marc 'BlackJack' Rintsch wrote: > In <[EMAIL PROTECTED]>, f pemberton > wrote: > > > I've tried using replace but its not working for me. > > xdata.replace('abcdef', 'highway') > > xdata.replace('defgef', 'news') > > xdata.replace('effwer', 'monitor') > > `replace()` does not work in place. You ha

Re: trouble with replace

2006-08-12 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, f pemberton wrote: > I've tried using replace but its not working for me. > xdata.replace('abcdef', 'highway') > xdata.replace('defgef', 'news') > xdata.replace('effwer', 'monitor') `replace()` does not work in place. You have to bind the result to a name like:: xdata