palindrome iteration

Paul Rubin no.email at nospam.invalid
Sat Aug 28 05:34:59 EDT 2010


Ian <hobson42 at gmaiil.com> 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
ugly.

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