Palindrome

Peter Otten __peter__ at web.de
Thu Nov 13 19:09:26 EST 2003


Ben Finney wrote:

> I have yet to try this on the world's longest palindrome:
> 
>     <http://www.norvig.com/palindrome.html>

>    is_pal = ( str == str[::-1] )

For really long palindromes, you might not want to reverse the whole string:

p.endswith(p[:len(p)//2:-1])

Peter




More information about the Python-list mailing list