In this Python list program, we will take a list of tuples as input and convert tuples in list into a sublist with the help of the below-given steps.
Convert tuples in list to sublist:
Steps to solve the program
- Take a list containing tuples as input.
- Using for loop convert tuples in list to sublist.
- If the iterated element has type tuple then use nested for lopp to iterate over elements in the tuple.
- Add the elements to the empty list using the append() function
- And add those lists as sublists to another list.
- Print the list to see the result.
#input list
list1 = [(3, 5), (6, 8), (8, 11), (12, 14), (17, 23)]
list2 = []
for value in list1:
if type(value) is tuple:
list3 = []
for var in value:
list3.append(var)
list2.append(list3)
#Printing output
print(list2)
Output :
[[3, 5], [6, 8], [8, 11], [12, 14], [17, 23]]
Related Articles
Python program to create a dictionary from a sublist in a given list.
Python program to replace ‘Java’ with ‘Python’ from the given list.
Python program to convert the 3rd character of each word to a capital case from the given list.
Python program to remove the 2nd character of each word from a given list.
Python program to get a length of each word and add it as a dictionary from the given list.
Python program to remove duplicate dictionaries from the given list.