list to string

Jeremy Hylton jeremy at alum.mit.edu
Tue Feb 27 03:58:58 CET 2001


>>>>> "gm" == glen mettler <glen.mettler at home.com> writes:

  gm> These commands will turn a string into a list: 
  gm> myword="dog"
  gm> mywordlist=list(myword)
  gm> result = ["d","o","g"]

  gm> is there a command/function that can take the list ["d","o","g"]
  gm> and make it a string "dog"?

string = "".join(result)

That is, call the join method of the empty string, passing it result
as an argument.

or

>>> "!".join(result)
'd!o!g'

Jeremy







More information about the Python-list mailing list