invert the order of a string

Dave Hansen iddw at hotmail.com
Mon Feb 13 18:55:37 EST 2006


On Mon, 13 Feb 2006 18:51:11 +0000 in comp.lang.python, rtilley
<rtilley at vt.edu> wrote:

>s = list('some_random_string')
>print s
>s.reverse()
>print s
>s = ''.join(s)
>print s
>
>Surely there's a better way to do this, right?

How about 

s = "some random string"
print s
s = s[::-1]
print s

HTH,
   -=Dave
                                        -=Dave

-- 
Change is inevitable, progress is not.



More information about the Python-list mailing list