string->list->string

Bjorn Pettersen BPettersen at NAREX.com
Mon Apr 23 20:36:48 EDT 2001


>>> x = [1,2,3]
>>> str(x)
'[1, 2, 3]'
>>> eval(str(x))
[1, 2, 3]
>>> s = "a!b%c^"
>>> import string
>>> t = string.maketrans(s,s)
>>> s.translate(t, "!%^")
'abc'
>>>

-- bjorn

-----Original Message-----
From: Courageous [mailto:jkraska1 at san.rr.com]
Sent: Monday, April 23, 2001 6:03 PM
To: python-list at python.org
Subject: string->list->string



So. I forget how to do this AGAIN. I know how to convert a string to a list:

mylist = str ("alpha")

but I don't remember the shorthand for converting it back?

On another note, is there a module somewhere that knows how to
strip an entire set of user-specified characters from a string, ala:

"a!b%c^".stripchars("!%^")

"abc"

???

C//

-- 
http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list