Palindrome

Alex Martelli aleax at aleax.it
Thu Nov 13 13:03:59 EST 2003


Pierre Quentel wrote:

> To remove the characters that are not alphanumeric I would have used
> filter :
> 
> t=filter(lambda x: x.isalnum(),list(s.lower()))

or perhaps more clearly...:

    t = [ c for c in s.lower() if c.isalnum() ]

Then, "list t comes from a palindromic string s" can be coded as:

    return t == t[::-1]

(in Python 2.3).


Alex





More information about the Python-list mailing list