![]() |
VOOZH | about |
Our task is to convert a list of characters into a single string. For example, if the input is ['H', 'e', 'l', 'l', 'o'], the output should be "Hello".
We can convert a list of characters into a string using join() method, this method concatenates the list elements (which should be string type) into one string.
Python
Explanation: ''.join(a) joins all elements in a using an empty string as the separator.
Table of Content
reduce() function applies a function cumulatively to the elements of the list, reducing them to a single value.
Python
Explanation:
If we want to join all the characters of the given list without using any inbuilt method then we can use a for loop.
Python
Explanation: Iterates through a, adding each character to res and builds the final string step by step.