Reversing a string

Martin Durkin nospam at williamsdurkin.co.uk
Sun Jul 1 02:47:49 EDT 2007


ptn <tn.pablo at gmail.com> wrote in news:1182997438.541012.54100
@o61g2000hsh.googlegroups.com:

> 
>>>> def rev(x):
>             mylist = []
>             for char in x:
>                  mylist.append(char)
>             mylist.reverse()
>             for letter in mylist:
>                  print letter
> 
> However, compare the incredible difference in clarity and elegance
> between that and:
> 
>> >>> print "\n".join("spam"[::-1])
> 

OK, maybe I'm missing the point here as I'm new to Python. The first one 
seems clearer to me. What am I missing?

Martin



More information about the Python-list mailing list