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
letters = ['h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'] sentence = ''.join(letters) print(sentence)
Output
This will give the output −
hello world