[Tutor] Re: Python question (when you have a free moment) (fwd)

Martijn Faassen m.faassen@vet.uu.nl
Mon, 23 Aug 1999 14:25:04 +0200


David Ascher wrote:
> 
> On Fri, 20 Aug 1999, Deirdre Saoirse wrote:
> 
> > A friend of mine, a molecular biologist, has a problem. He has a file,
> > approximately 1.5mb, that has a bunch of returns in it (which interfere
> > with his ability to perform raw searches).
> 
> 1.5M isn't that big.
> 
> Why not just:
[string.split based code snipped]

If you're still interested in why your old method didn't provide much of
a speedup, I think the cause may lie in the continuous use of string
concatenation; a new string needs to be created all the time, and the
(possibly vast) contents of the old string would have to be copied over.
A quicker way is to use the array module, which has an array of
characters to which you can add strings. This uses smart allocation code
(like Python's list internally does), and isn't as heavy in memory use
as using a straight list.

Regards,

Martijn