From: tim_one at email.msn.com (Tim Peters)
Date: Mon, 26 Apr 1999 02:26:05 GMT
Subject: Handling backspace chars in a string...
In-Reply-To: <3723bd8c.603427371@news2.bga.com>
References: <3723bd8c.603427371@news2.bga.com>
Message-ID: <000201be8f8c$22f186c0$d5a02299@tim>
Content-Length: 1307
X-UID: 683                                                  

[Purple]
> I didn't post the code for that bit [newlines] as it seems easy enough
> to take care of processing those with something like
> map(string.strip,string.split(stringWithNewlines,"\n")
>
> Unless there's a better way to do that too? :)

I don't know what you're trying to do.  What that code *does* is break the
string into chunks as separated by newlines, strips leading and trailing
whitespace of all kinds from each resulting chunk, and leaves the result as
a list of strings.  That doesn't sound like what you *wanted* to do, but if
it is I can't think of a better to do that <wink>.

> ...
> [code using lists snipped]
> I may well go that route... Is it any slower or faster to do this
> using lists rather than counting up the backspaces and slicing around
> the bits that need to be snipped?

from time import clock

How big are the strings?  What's the expected distribution of backspaces?
Etc.  The list code is worst-case linear-time (in practice although not in
theory); the string slicing worst-case quadratic (although "acts linear"
until strings reach a platform-dependent size).  There's no definitive
answer to which is faster without a strong characterization of your data.
Don't bother telling me, time it <wink>.

in-the-end-is-it-faster-to-run-or-walk?-yes-ly y'rs  - tim






