palindrome iteration

Cousin Stanley cousinstanley at gmail.com
Mon Sep 13 17:52:57 CEST 2010


> To deal with "real" palindromes such as, "Madam, I'm Adam," 
> you should probably strip all spaces and punctuation:
>
> # untested
> pat = re.compile(r'[a-z]')
> def is_palindrome(s):
>     letters = pat.findall(s.lower())
>     return letters == reversed(letters)

  Using python 2.5 the above solution always returned False
  for me until the  reversed( letters )  iterator was explicitly
  coerced into a list .... 

    return letters == list( reversed( letters ) ) 
 

-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona




More information about the Python-list mailing list