Re: A simple question string.replace
- From: bruno at modulix <onurb@xxxxxxxxxxx>
- Date: Tue, 31 Jan 2006 11:07:55 +0100
Haibao Tang wrote:
> I have a two-column data file like this
> 1.1 2.3
> 2.2 11.1
> 4.3 1.1
> ...
> Is it possible to substitue all '1.1' to some value else without using
> re.
I suppose that you don't want '11.1' to be affected.
raw_data="""
1.1 2.3
2.2 11.1
4.3 1.1
"""
data = filter(None, [line.strip().split() \
for line in raw_data.split('\n')])
processed = [[item == '1.1' and 'X.X' or item for item in pair] \
for pair in data]
result = "\n".join(["\t".join(pair) for pair in processed])
Not sure this is the fastest solution...
BTW, may I ask why you don't want to use regexp ?
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb@xxxxxxxxxxx'.split('@')])"
.
- References:
- A simple question string.replace
- From: Haibao Tang
- A simple question string.replace
- Prev by Date: Re: beta.python.org content
- Next by Date: Re: test whether 2 objects are equal
- Previous by thread: Re: A simple question string.replace
- Next by thread: wxPython Conventions
- Index(es):
Relevant Pages
|