Program to flatten a list of lists into a tuple

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

Steps to solve the program
  1. Take a list of lists as input and create an empty list.
  2. Use a for loop to iterate over the list in the lists.
  3. Use a nested for loop to iterate over elements in each list.
  4. Add elements to the empty list using append().
  5. Convert the new list to a tuple using tuple().
  6. Print the output.
				
					l = [['s'],['q'],['a'],['t'],['o'],['o'],['l'],['s']]
print("List of lists: ",l)
l1 = []
for lists in l:
    for char in lists:
        l1.append(char)
tup = tuple(l1)
print("Tuple: ",tup)
				
			

Output :

				
					List of lists:  [['s'], ['q'], ['a'], ['t'], ['o'], ['o'], ['l'], ['s']]
Tuple:  ('s', 'q', 'a', 't', 'o', 'o', 'l', 's')
				
			

multiply ith element from each tuple from a list of tuples.

flatten a tuple list into a string.

Leave a Comment