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 −

Example

 Live Demo

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

Output

This will give the output −

hello world
raja
Published on 03-Aug-2018 11:36:38
Advertisements