palindrome iteration

D'Arcy J.M. Cain darcy at druid.net
Sat Aug 28 09:32:57 EDT 2010


On Sat, 28 Aug 2010 09:48:47 +0100
Ian <hobson42 at gmaiil.com> wrote:
> > def palindromep(s):
> >      def reversed(s):
> >          return s[::-1]
> >      return s == reversed(s)
> I like this.
> 
> s[::-1] is obscure and non-obvious, especially to Python noobs.
> 
> This makes it clear what is going on and why at a cost of very little code.

It seems unnecessary to me.  Even if you can't figure it out through
simple inspection, it takes seconds to fire up Python and type "print
'abc'[::-1]" into it to see what that does. Then you have another tool
in your toolbox.

-- 
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