[Tutor] detecing palindromic strings

Tiago Saboga tiagosaboga at terra.com.br
Sat Sep 29 02:39:01 CEST 2007


On Fri, Sep 28, 2007 at 04:59:26PM -0700, Christopher Spears wrote:
> How do I get around this?  Is there a better way to
> write this script?  I can't figure out how to loop
> through a string starting from the last character.

A string is a sequence of chars, and you can use slices with it [1].

In [23]: a = 'abcdef'

In [24]: a[::-1]
Out[24]: 'fedcba'

Tiago.

[1] - http://docs.python.org/lib/typesseq.html



More information about the Tutor mailing list