[Tutor] Program for outputing the letter backward - almost there!

Adam adam.jtm30 at gmail.com
Wed Mar 29 23:29:27 CEST 2006


I just wanted to throw in a couple of ideas for you on this subject.
These are the ways I would personally think of going about this
problem:

>>> ''.join([s[n] for n in range(len(s)-1, -1, -1)])
'rac'
Which looks a bit fugly but is nice and short if you can manage list comps.

and now my favourite:

>>> l = list("car")
>>> l.reverse()
>>> ''.join(l)
'rac'

hth


More information about the Tutor mailing list