On Fri, 27 Aug 2010 16:43:16 +0200 Bruno Desthuilliers <bruno.42.desthuilli...@websiteburo.invalid> wrote: > Dave Angel a écrit : > > def is_palindrom(s): > > s = s.lower() > > return s == s[::-1] > > > Right, go on, make me feel a bit more stupid :-/ > Who's next ?
How about a one-liner? is_palindrome = lambda x: len(x)> 0 and x == x.lower()[::-1] Note that the above assumes that single characters are palindromes but empty strings are not. I'm not 100% sure that that last is true. If not then this can be simplified. is_palindrome = lambda x: x == x.lower()[::-1] -- D'Arcy J.M. Cain <da...@druid.net> | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list