palindrome iteration

D'Arcy J.M. Cain darcy at druid.net
Fri Aug 27 21:42:18 CEST 2010


On Fri, 27 Aug 2010 12:02:39 -0400
"D'Arcy J.M. Cain" <darcy at druid.net> wrote:
> On Fri, 27 Aug 2010 11:49:42 -0400
> "D'Arcy J.M. Cain" <darcy at druid.net> wrote:
> > is_palindrome = lambda x: x == x.lower()[::-1]
> 
> Oops.  Simple and wrong.
> 
> is_palindrome = lambda x: x.lower() == x.lower()[::-1]

slightly more efficient I think.

is_palindrome = lambda y: (lambda x: x == x[::-1])(y.lower())

-- 
D'Arcy J.M. Cain <darcy at 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.



More information about the Python-list mailing list