--
- 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
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':
>>> 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
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
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
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
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
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