Python | Convert a list of characters into a string

28 Jun, 2022
Given a list of characters, merge all of them into a string. Examples:
Input : ['g', 'e', 'e', 'k', 's', 'f', 'o', 
             'r', 'g', 'e', 'e', 'k', 's']
Output : geeksforgeeks 

Input : ['p', 'r', 'o', 'g', 'r', 'a', 'm', 
                        'm', 'i', 'n', 'g']
Output : programming 
Method 1 : Traversal of list
Initialize an empty string at the beginning. Traverse in the list of characters, for every index add character to the initial string. After complete traversal, print the string which has been added with every character. 
Python
# Python program to convert a list# of character def convert(s):     # initialization of string to ""    new = ""     # traverse in the string    for x in s:        new += x     # return string    return new          # driver codes = ['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']print(convert(s))
Output:
geeksforgeeks
Time Complexity: O(n)
Chapters
descriptions off, selected
captions settings, opens captions settings dialog
captions off, selected
English
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
Auxiliary Space: O(n)
Method 2 : Using join() function
By using join() function in python, all characters in the list can be joined. The syntax is:
str = ""
str1 = ( "geeks", "for", "geeks" )
str.join(str1) 
The list of characters can be joined easily by initializing str=”” so that there are no spaces in between. 
Python
# Python program to convert a list# of character def convert(s):     # initialization of string to ""    str1 = ""     # using join function join the list s by    # separating words by str1    return(str1.join(s))     # driver codes = ['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']print(convert(s))
Output:
geeksforgeeks
Time Complexity: O(n)
Auxiliary Space: O(n)
                                                                                                              Method#3: Using reduce() function
Reduce function is used to convert the iterables to reduce in a single cumulative value. 
Python3
# Python program to convert a list# of characterimport functools def convert(s):     # Using reduce to jion the list s to string    str1 = functools.reduce(lambda x,y : x+y, s)     # Return string 1    return str1     # driver codes = ['g', 'e', 'e', 'k', 's', 'f', 'o', 'r', 'g', 'e', 'e', 'k', 's']print(convert(s))
Output:
geeksforgeeks
Convert a list of characters into a string in Python | GeeksforGeeks - YouTubeGeeksforGeeks531K subscribersConvert a list of characters into a string in Python | GeeksforGeeksWatch laterShareCopy linkInfoShoppingTap to unmuteIf playback doesn't begin shortly, try restarting your device.More videosMore videosYou're signed outVideos you watch may be added to the TV's watch history and influence TV recommendations. To avoid this, cancel and sign in to YouTube on your computer.CancelConfirmSwitch cameraShareInclude playlistAn error occurred while retrieving sharing information. Please try again later.Watch on0:000:000:00 / 4:53•Live•<div class="player-unavailable"><h1 class="message">An error occurred.</h1><div class="submessage"><a href="https://www.youtube.com/watch?v=MsFdb1r8ytQ" target="_blank">Try watching this video on www.youtube.com</a>, or enable JavaScript if it is disabled in your browser.</div></div>
nidhi_biet
riya55
satyam00so
Python list-programs
Python string-programs
python-list
python-string
Python
Strings
python-list
Strings
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.