palindrome function
Terry Reedy
tjreedy at udel.edu
Sat Jul 12 22:02:54 EDT 2008
Mensanator wrote:
> It hasn't. and here's why:
>
> IDLE 2.6b1
>>>> seq=['a','n','n','a']
>>>> seq.reversed()
>
> Traceback (most recent call last):
> File "<pyshell#3>", line 1, in <module>
> seq.reversed()
> AttributeError: 'list' object has no attribute 'reversed'
My apologies. reversed() is a builtin func, not a method, and it
produces an iterator, not a seq. SO, corrected,
>>> for s in ((1,2,3,2,1), [1,2,3,2,1]):
... type(s)(reversed(s)) == s
...
True
True
>>> s = '12121'
>>> ''.join(reversed(s)) == s
True
More information about the Python-list
mailing list