in-place string reversal
Sion Arrowsmith
siona at chiark.greenend.org.uk
Tue Mar 28 10:03:23 EST 2006
Sathyaish <sathyaish at gmail.com> wrote:
>How would you reverse a string "in place" in python?
> [ ... ]
>Forget it! I got the answer to my own question. Strings are immutable,
>*even* in python.
I'm not sure what that "*even*" is about, but glad that "You can't,
strings are immutable" is a satisfactory answer. Rather than writing
your own reversing code, you might like to look at:
>>> "".join(reversed("foo"))
--
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
More information about the Python-list
mailing list