![]() |
Available news archives:
comp.lang.tcl
-
comp.lang.python
-
comp.security.firewalls
-
sci.crypt -
comp.lang.php -
comp.lang.javascript
|
|
comp.lang.python archiveRe: in-place string reversal
From: Adam DePrince <adam.deprince@gmail.com>
Date: Tue Mar 28 2006 - 18:00:57 CEST
On Tue, 2006-03-28 at 06:15 -0800, Sathyaish wrote:
How big is your string?
For short strings (i.e. where large means you don't have enough RAM to
>>> "Abc"[::-1]
Also, anytime you reach for a for-loop to build a string step by step,
strText = "foo"
Each loop you are copying the string again, the timing behavior of your
If you are really concerned about memory allocation, well, I don't know
strTemp = chr + strTemp
you are throwing away your old copy and building a new copy. Ouch.
Forgive me for preaching, but you just committed the grievous act of
One of the advantages of using a high level language is you get to leave
In my experience I've found that when under time pressure python
As for mutability, immutability is a big virtue and performance gain.
Also, consider some other side effects of mutable strings.
>> s = "Abc"
Now if strings were mutable:
>> s = "Abc"
Other users of s between assignment and reversal (like
Cheers - Adam DePrince
|