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

Fredrik Lundh fredrik at
Thu Oct 19 19:47:37 CEST 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



More information about the Python-list mailing list