Python program to convert list of string list to string list

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

To convert a list of string lists to a string list, we can use a nested loop and the join() method in Python. Here is an example Python program that does this: 

 

# Define a list of string lists
list_of_string_lists = [['hello', 'world'], ['how', 'are', 'you']]

# Define an empty list to store the string list
string_list = []

# Loop through each string list in the list of string lists
for lst in list_of_string_lists:
    # Join the strings in the string list using a space as the delimiter
    # and append the resulting string to the string list
    string_list.append(' '.join(lst))

# Print the string list
print(string_list)

In this program, we first define the list of string lists as list_of_string_lists. We then define an empty list string_list to store the resulting string list.

We then loop through each string list in the list of string lists using a for loop. For each string list, we use the join() method to join the strings in the list using a space as the delimiter. We then append the resulting string to the string list.

Finally, we print the resulting string list using the print() function.

When we run this program, the output will be: 

 

['hello world', 'how are you']

which is the desired string list.

Submit Your Programming Assignment Details