Python program to convert a list of characters into a string

PythonProgrammingServer Side Programming

Python requires this kind of conversion a lot. For example, such conversions are useful for serialization purposes. An example of such a conversion would be −

['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'] to "hello world"

Python has a join method that can be used for such conversions. It can be applied on a delimiter string that'll be used to concatenate the objects together. In this case, we need an empty delimiter string. We can implement it as follows −


 Live Demo

letters = ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd']
sentence = ''.join(letters)


This will give the output −

hello world
Updated on 20-Jun-2020 08:56:40