Reversing a string
Alex Martelli
aleax at mac.com
Sun Jul 1 17:47:50 EDT 2007
Jay Loden <python at jayloden.com> wrote:
...
> For what it's worth, with python 2.5 on my Macbook:
Hmmm, doesn't look to me as if it's worth much...:
> [jloden at macbook jloden]$ python -m timeit 's = "onomatopoeia"; s =
s.join(s[::-1])'
since what you're doing is...:
>>> s = "onomatopoeia"
>>> s = s.join(s[::-1])
>>> s
'aonomatopoeiaionomatopoeiaeonomatopoeiaoonomatopoeiaponomatopoeiaoonoma
topoeiatonomatopoeiaaonomatopoeiamonomatopoeiaoonomatopoeianonomatopoeia
o'
>>>
...which isn't really just reversing the string, but quite a bit more
work!-)
Alex
More information about the Python-list
mailing list