Python | Convert list of tuples to list of list

Convert List of Tuples to List of List : 

Given a list of tuples, write a Python program to convert it into a list of list. we can perform this operation using various Methods. 

Example : 

  • a=[ ( 1, 2) , ( 3 ,4) ]
    • a = [ [1,2] ,[3,4 ] ]
Convert List of Tuples to List of List

Method #1 : 

This can easily be achieved using the list comprehension. We just iterate through each tuple of the list convert the tuples to the list.

#Python Program 
#rishikesh 
# Python code to convert list of tuples into list of list 

 

  
# List of tuple  
tup = [(‘A’2), (‘B’4), (56)] 
print(‘The orignal list of tuple is :’ , tup)
# using list comprehension 
# convert list of tuples to list of list 
res = [list(ele) for ele in tup] 
print(“The list of list :” ,res) 

Output :

The orignal list of tuple is : [('A', 2), ('B', 4), (5, 6)]
The list of list : [['A', 2], ['B', 4], [5, 6]]
 

Method #2 : 

We can use the map function and list operator to perform this particular task. The map function binds each tuple and converts it into a list.

#Python Program 
#rishikesh 
# Python code to convert list of tuples into list of list 

 

 
# List of tuple  
tup = [(‘A’2), (‘B’4), (56)] 
print(‘The orignal list of tuple is :’ , tup)
# using map() + list 
# convert list of tuples to list of list 
res = list(map(list, tup)) 
print(“The list of list :” ,res) 

Output :

The orignal list of tuple is : [('A', 2), ('B', 4), (5, 6)]
The list of list : [['A', 2], ['B', 4], [5, 6]]