palindrome iteration

Paul Rubin at nospam.invalid
Sat Aug 28 11:34:59 CEST 2010

Ian <hobson42 at> writes:
>  On 27/08/2010 21:51, Jussi Piitulainen wrote:
>> Meanwhile, I have decided to prefer this:
>> 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.

Overriding the 'reversed' builtin even in an inner scope is a little bit

If you don't mind some overhead, list(s)==list(reversed(s)) (using the
built-in reversed, not the special obscure one) is pretty clear.

More information about the Python-list mailing list