Re: trouble with replace

2006-08-13 Thread Anthra Norell
-- - Original Message - From: "f pemberton" <[EMAIL PROTECTED]> Newsgroups: comp.lang.python To: Sent: Saturday, August 12, 2006 6:49 PM Subject: trouble with replace > I have a string (xdata) and theres a newline after every 17 characters > of the st

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

trouble with replace

2006-08-12 Thread f pemberton
I have a string (xdata) and theres a newline after every 17 characters of the string. I was wondering how I can replace multiple substrings multiple times within a string? To put it another way, this is what i want to do. Substring to find ("abcdef") replace it with ("highway") search again, subst