How to convert list to string

PythonStringList

Python Problem Overview


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

Python Solutions


Solution 1 - Python

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)

Solution 2 - Python

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

Solution 3 - Python

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNm3View Question on Stackoverflow
Solution 1 - PythonSenthil KumaranView Answer on Stackoverflow
Solution 2 - PythonAndrey SboevView Answer on Stackoverflow
Solution 3 - PythonNathanView Answer on Stackoverflow