In this python tuple program, we will convert a list of tuples to a list of lists.
Steps to solve the program
- Take a list of tuples as input and create an empty list.
- Use a for loop to iterate over tuples in the list.
- Add the tuples to the empty list using append() after converting them to a list using list().
- Print the output.
l = [(1,5),(7,8),(4,0)]
l1 = []
print("Original list: ",l)
for tup in l:
l1.append(list(tup))
print("After converting tuples inside a list to list: ",l1)
Output :
Original list: [(1, 5), (7, 8), (4, 0)]
After converting tuples inside a list to list: [[1, 5], [7, 8], [4, 0]]