Joining elements in a list to 1 element

dimitri pater dimitri.pater at
Thu Aug 23 11:49:59 CEST 2007

Dear all,
I am having trouble joining elements in a list into 1 element.
e.g. ['a','b','c'] into ['abc'] so that len(list) returns 1

I have tried the following:
myList = ['a','b','c']
print myList
>>>['a', 'b', 'c']
# get type
print type(myList)
>>><type 'list'>
# get length
print len(myList)

myList2 = ''.join(myList)
print myList2
# get type
print type(myList2)
>>><type 'str'>
# get length
print len(myList2)

As you can see, the type 'list' turns into 'str' after .join. Doing
something like list(''.join(myList)) returns the type 'list' but still has 3


You can't have everything. Where would you put it? -- Steven Wright
please visit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list