The Wayback Machine - https://web.archive.org/web/20221102042140/https://www.geeksforgeeks.org/python-convert-list-of-string-list-to-string-list/
Skip to content
Related Articles

Related Articles

Python | Convert List of String List to String List

View Discussion
Improve Article
Save Article
  • Difficulty Level : Basic
  • Last Updated : 05 Sep, 2022
View Discussion
Improve Article
Save Article

Sometimes while working in Python, we can have problems of the interconversion of data. This article talks about the conversion of list of List Strings to joined string list. Let’s discuss certain ways in which this task can be performed. 

Method #1 : Using map() + generator expression + join() + isdigit() 

This task can be performed using a combination of the above functions. In this, we join the numbers using join and construct a string integers. The map() is used to apply logic to each element in list. 

Python3




# 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))

Output : 

The original list : ['[1, 4]', '[5, 6]', '[7, 10]']
List after performing conversion : ['14', '56', '710']

Method #2: Using eval() + list comprehension 

The combination of above functionalities can be used to perform this task. In this, eval() interprets each strings as list and then we can convert that list to strings using join(). List comprehension is used to iterate through the list. 

Python3




# 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))

Output : 

The original list : ['[1, 4]', '[5, 6]', '[7, 10]']
List after performing conversion : ['14', '56', '710']

Method #3: Using enumerate function

Python3




test_list = ["[1, 4]", "[5, 6]", "[7, 10]"]
res = [''.join(str(b) for b in eval(a)) for i, a in enumerate(test_list)]
print(res)

Output

['14', '56', '710']

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!