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

Paul Rubin http
Thu Oct 19 18:09:49 CEST 2006

rick <ath-admin at> writes:
> Why can't Python have a reverse() function/method like Ruby?
> Python:
> x = 'a_string'
> # Reverse the string
> print x[::-1]
> The Ruby approach makes sense to me as a human being. The Python
> approach is not easy for me (as a human being) to remember. Can that
> be changed or should I just start blindly memorizing this stuff?

You could use:

   print ''.join(reversed(x))

That also looks a little bit weird, but it combines well-known Python
idioms straightforwardly.

More information about the Python-list mailing list