in-place string reversal

Martin P. Hellwig mhellwig at xs4all.nl
Tue Mar 28 09:29:08 EST 2006


Sathyaish wrote:
> And that the "extra-memory" operation I've given above is expensive, I
> believe. Is there an efficient way to do it?
> 
If i recall correctly a string is an immutable list.
I would do it this way:
 >>> strTXT = "foo"
 >>> strREV = strTXT[::-1]
 >>> strREV
'oof'

-- 
mph



More information about the Python-list mailing list