Python | Convert List of lists to list of Strings

Interconversion of data is very popular nowdays and has many applications. In this scenario, we can have a problem in which we need to convert a list of lists, i.e matrix into list of strings. Let’s discuss certain ways in which this task can be performed.

Method #1 : Using list comprehension + join()
The combination of above functionalities can be used to perform this task. In this, we perform the task of iteration using list comprehension and join() is used to perform task of joining string to list of strings.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 code to demonstrate working of
# Convert List of lists to list of Strings
# using list comprehension + join()
  
# initialize list 
test_list = [["g", "f", "g"], ["i", "s"], ["b", "e", "s", "t"]]
  
# printing original list 
print("The original list : " + str(test_list))
  
# Convert List of lists to list of Strings
# using list comprehension + join()
res = [''.join(ele) for ele in test_list]
  
# printing result
print("The String of list is : " + str(res))

chevron_right


Output :



The original list : [['g', 'f', 'g'], ['i', 's'], ['b', 'e', 's', 't']]
The String of list is : ['gfg', 'is', 'best']

 

Method #2: Using map() + join()
The task above can also be performed using combination of above methods. In this, we perform the task of conversion using join and iteration using map().

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python3 code to demonstrate working of
# Convert List of lists to list of Strings
# using map() + join()
  
# initialize list 
test_list = [["g", "f", "g"], ["i", "s"], ["b", "e", "s", "t"]]
  
# printing original list 
print("The original list : " + str(test_list))
  
# Convert List of lists to list of Strings
# using map() + join()
res = list(map(''.join, test_list))
  
# printing result
print("The String of list is : " + str(res))

chevron_right


Output :

The original list : [['g', 'f', 'g'], ['i', 's'], ['b', 'e', 's', 't']]
The String of list is : ['gfg', 'is', 'best']



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.