Program to flatten a list of tuples into a string

In this python tuple program, we will flatten a list of tuples into a string.

Steps to solve the program
  1. Take a list of tuples as input and create an empty string.
  2. Use a for loop to iterate over the tuples in the list.
  3. Use a nested for loop to iterate over characters in the tuples.
  4. Add the characters to the string.
  5. Print the output.
				
					l = [('s','q','a'),('t','o'),('o','l','s')]
print("Original list of tuples: ",l)
str1 = ""
for tup in l:
    for char in tup:
        str1 += char+" "
print("New string: ",str1)
				
			

Output :

				
					Original list of tuples:  [('s', 'q', 'a'), ('t', 'o'), ('o', 'l', 's')]
New string:  s q a t o o l s 
				
			

flatten a list of lists into a tuple.

convert a tuple into a list by adding the string after every element of the tuple.

Leave a Comment