jpiitula at ling.helsinki.fi
Fri Aug 27 22:51:17 CEST 2010
> On 27/08/2010 20:43, Jussi Piitulainen wrote:
>> Dave Angel writes:
>>> Jussi Piitulainen wrote:
>>>> Agreed. But is there any nicer way to spell .reverse than [::-1]
>>>> in Python? There is .swapcase() but no .reverse(), right?
>>> There can't be a .reverse() method on string, because it's
>>> immutable. You could use
>>> but I'd prefer pal[::-1] as I said earlier.
>> There could easily be a .reverse() method on strings. It would
>> return the reversed string, like .swapcase() returns the swapcased
> Lists have a .reverse method, but it's an in-place reversal. In
> order to reduce confusion, a string method which returned the string
> reversed would be better called .reversed().
Meanwhile, I have decided to prefer this:
return s == reversed(s)
More information about the Python-list