Python reverse string method
Sep 25th, 2006 by jbloom
Saw this easy way to reverse a string in python today, over at Answer My Searches
Here’s how to do it:
exampleString = 'Hey there fancy pants' reversedString = exampleString[::-1] print reversedString >> stnap ycnaf ereht yeH
This works because a String is a sequence type in python and you can apply all the ’slicing’ syntax you want to it. So in this case [::-1] is saying, taking the string sequence start from the beginning ‘:’ go to the end ‘:’ and step through it in reverse (-1).
just so you know….
http://37signals.com/svn/archives2/reflections_are_the_new_drop_shadows.php