In this python tuple program, we will convert a list of lists to a tuple of tuples.
Steps to solve the program
- Take a list of lists as input and create an empty list.
- Use a for loop to iterate over lists in the list.
- Add the list to the empty list using append() after converting it to a tuple using tuple().
- Now convert the new list to a tuple using tuple().
- Print the output.
l = [['sqatools'],['is'],['best']]
print("List of lists: ",l)
l1 = []
for lists in l:
l1.append(tuple(lists))
tup = tuple(l1)
print("Tuple of tuples: ",tup)
Output :
List of lists: [['sqatools'], ['is'], ['best']]
Tuple of tuples: (('sqatools',), ('is',), ('best',))
extract tuples that are symmetrical with others from a list of tuples.