palindrome iteration

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Fri Aug 27 16:41:28 CEST 2010


Richard Arts a écrit :
>> Now there is another solution. A palindrom is made of two symetric halves,
>> with (odd len) or without (even len) a single char between the symetric
>> halves, ie :
>>
>> * odd : ABCBA ('AB' + 'C' + 'BA')
>> * even : ABCCBA ('ABC' + 'CBA')
>>
>> So you just have to extract the symetric halves, reverse one, and compare
>> both (case insensitive compare while we're at it).
> 
> Yes, this is a correct observation, but it is not necessary to compare
> the halves; Simply compare the complete string with its reverse. If
> they match, it is a palindrome.

Duh :(

I kinda feel stupid right now, thanks Richard :-/





More information about the Python-list mailing list