convert a list to a string?

Roy Smith roy at panix.com
Thu Mar 3 22:11:21 EST 2005


Anthony Liu <antonyliu2002 at yahoo.com> wrote:

> Suppose I have a list 
> 
> myList = ["this", "is", "a", "sample", "list"]
> 
> If I don't want to iterate through it and concatenate
> the list elements, how do I easily convert it to a
> string like
> 
> "this is a sample list"

You want:

>>> myList = ["this", "is", "a", "sample", "list"]
>>> " ".join (myList)
'this is a sample list'



More information about the Python-list mailing list