list to string

Sheila King sheila at spamcop.net
Tue Feb 27 08:22:03 CET 2001


On Tue, 27 Feb 2001 07:16:22 GMT, "Wayne Izatt"
<wayne.izatt at _nospam_myself.com> wrote in comp.lang.python in article
<avIm6.174966$df5.5092180 at news1.crdva1.bc.home.com>:

:"glen mettler" <glen.mettler at home.com> wrote in message
:news:1103_983241679 at cc462845-a...
:> These commands will turn a string into a list:
:> myword="dog"
:> mywordlist=list(myword)
:> result = ["d","o","g"]
:>
:> is there a command/function that can take the list ["d","o","g"] and make
:it a string "dog"?
:
:>>> lst =["d", "o", "g"]
:>>> lst
:['d', 'o', 'g']
:>>> dog = lst[0]+lst[1]+lst[2]
:>>> dog
:'dog'
:
:or is there something I'm not getting?

Your method would be awfully tedious for very long strings. You want something
that will be easy to implement, regardless of the length of the string.
Fortunately, several others in this thread have already suggested using the
join command from the string methods.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




More information about the Python-list mailing list