string->list->string
Courageous
jkraska1 at san.rr.com
Mon Apr 23 21:35:38 EDT 2001
On Mon, 23 Apr 2001 18:36:48 -0600, Bjorn Pettersen <BPettersen at NAREX.com> wrote:
>>>> x = [1,2,3]
>>>> str(x)
>'[1, 2, 3]'
>>>> eval(str(x))
>[1, 2, 3]
Not getting it: I want
s = "abc"
l = list(s)
<something>(l)
"abc"
Where something is some expression. The worst part here is that sometime in
the last year, I've asked this very same question before. *IRK* Is this in the FAQ?
It outta be.
>>>> s = "a!b%c^"
>>>> import string
>>>> t = string.maketrans(s,s)
>>>> s.translate(t, "!%^")
>'abc'
Hrm. I read the documentation for string.maketrans() and string.translate() just now.
I don't get it. The documentation doesn't make this clear, and I don't understand
from your example what's going on. While I can see that it works, I don't get the
basic principle. I would think a maketrans of s,s would just translate one character
to the same character.
???
C//
More information about the Python-list
mailing list