Palindrome

Peter Otten __peter__ at web.de
Fri Nov 14 01:09:26 CET 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