[Tutor] reversing a string
Max Noel
maxnoel_fr at yahoo.fr
Sat Oct 9 01:32:24 CEST 2004
On Oct 8, 2004, at 23:46, Kirk Bailey wrote:
> ok, something struck a spark in my concrete enshrouded skull; how does
> one reverse a string.
>
> Consider a string:'qwerty'. A SIMPLE and FAST process to reverse it. I
> considered appending and recursion, but there ought to be a better
> way, although dealing off the bottom of the deck does have a peverse
> attraction to it (slicing and taking -1 char off the string and
> appending it to a string).
>
> Anyone want to discuss this task?
I have a simple way of doing this. There's probably a better one, I'm
sure this can be done as a one-liner. Anyway, here goes:
foo = "Hello World!"
bar = list(foo)
bar.reverse()
baz = "".join(bar)
-- Wild_Cat
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting
and sweating as you run through my corridors... How can you challenge a
perfect, immortal machine?"
More information about the Tutor
mailing list