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

Fredrik Lundh fredrik at pythonware.com
Thu Oct 19 13:47:37 EDT 2006


Dennis Lee Bieber wrote:

> 	ONE usage... The old intro-to-programming Palindrome detector
> becomes a very simple assignment given an easy means of reversing a
> string (vs the "expected" loop comparing from the ends in to the center)

you mean like

 >>> s = "a man a plan a canal panama"
 >>> if list(s) != list(reversed(s)):
...     print repr(s), "is not a palindrome"
...
'a man a plan a canal panama' is not a palindrome

?

</F>




More information about the Python-list mailing list