Help with String Manipulation

William Tanksley wtanksle at
Wed Jun 23 03:26:01 CEST 1999

On Wed, 23 Jun 1999 01:06:25 GMT, Doug Stanfield wrote:
>If you're new to Python it might seem like some magic in this:

>>>> testring = "This is an example"
>>>> testlist = map (ord, testring)
>>>> testlist.reverse()
>>>> import array
>>>> finalstring = array.array('b', testlist).tostring()

Whew!  Is there any reason to not use:

>>> x = list("This is an example.")
>>> x.reverse()
>>> import string
>>> string.join(x,"")


In other words, since a string is immutable, just convert the string to a
list explicitly.

If you MUST be obscure, try this:

>>> x = map(None, "This is an example.")
>>> x.reverse()

This way you don't have to play with ordinals.


-William "Billy" Tanksley
Utinam logica falsa tuam philosophiam totam suffodiant!
   :-: May faulty logic undermine your entire philosophy!

More information about the Python-list mailing list