palindrome iteration

Jussi Piitulainen jpiitula at
Sat Aug 28 08:57:26 CEST 2010

Richard Arts writes:

> On Fri, Aug 27, 2010 at 10:51 PM, Jussi Piitulainen wrote:
>> Meanwhile, I have decided to prefer this:
>> def palindromep(s):
>>    def reversed(s):
>>        return s[::-1]
>>    return s == reversed(s)
> That seems like a bit of overkill... Why would you want to define a
> function in a function for something trivial like this? Just
> def palindrome(s):
>     return s[::-1]
> will do fine.

I'm sure your version will do something just fine, but what that
something is, I can not tell. The body of your version is quite
obscure and does not seem to agree with the name of the function.

I find (s == reversed(s)) a clearer expression than (s == s[::-1]),
and I found a simple way to use my preferred expression.

> Of course, you can stick the inner function in a library somewhere
> if you like.

>From my point of view, it would be an understatement to say that
setting up a library for this would be an overkill. A simple local
auxiliary function is nothing.

More information about the Python-list mailing list