Convert a list of characters into a string

nos picture nos · Dec 19, 2010 · Viewed 796.6k times · Source

If I have a list of chars:

a = ['a','b','c','d']

How do I convert it into a single string?

a = 'abcd'

Answer

Daniel Stutzbach picture Daniel Stutzbach · Dec 19, 2010

Use the join method of the empty string to join all of the strings together with the empty string in between, like so:

>>> a = ['a', 'b', 'c', 'd']
>>> ''.join(a)
'abcd'