invert the order of a string

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Mon Feb 13 21:50:11 EST 2006


Paul Rubin a écrit :
> rtilley <rtilley at vt.edu> writes:
> 
>>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?
> 
> 
> In Python 2.4, just say
>   s = reversed('some_random_string')

Python 2.4.1 (#1, Jul 23 2005, 00:37:37)
[GCC 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6)] on 
linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>> reversed('some_random_string')
<reversed object at 0x4040f30c>
 >>>

Yes, that was my first take too - but I jumped to my Python shell before 
posting !-)



More information about the Python-list mailing list