How to convert list to string [duplicate] – Dev

The best answers to the question “How to convert list to string [duplicate]” in the category Dev.

QUESTION:

How can I convert a list to a string using Python?

ANSWER:

>>> L = [1,2,3]       
>>> " ".join(str(x) for x in L)
'1 2 3'

ANSWER:

By using ''.join

list1 = ['1', '2', '3']
str1 = ''.join(list1)

Or if the list is of integers, convert the elements before joining them.

list1 = [1, 2, 3]
str1 = ''.join(str(e) for e in list1)

ANSWER:

L = ['L','O','L']
makeitastring = ''.join(map(str, L))