Help with String Manipulation
William Tanksley
wtanksle at dolphin.openprojects.net
Tue Jun 22 21:26:01 EDT 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.
>-Doug-
--
-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