invert or reverse a string... warning this is a rant

Ron Adam rrr at ronadam.com
Thu Oct 19 14:59:52 EDT 2006


James Stroud wrote:

> Of course, I think str.join can operate on iterators, as Paul Rubin 
> suggests:
> 
>  > print ''.join(reversed(x))
> 
> This latter approach still seems a little clunky, though.
> 
> James

Slices can be named so you could do...

 >>> reverser = slice(None, None, -1)
 >>>
 >>> 'abcdefg'[reverser]
'gfedcba'


Ron



More information about the Python-list mailing list