Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python | Convert list of tuples to list of list

  • Last Updated : 27 Mar, 2019

This is a quite simple problem but can have a good amount of application due to certain constraints of python language. Because tuples are immutable, they are not easy to process whereas lists are always a better option while processing. Let’s discuss certain ways in which we can convert a list of tuples to list of list.

Method #1 : Using list comprehension
This can easily be achieved using the list comprehension. We just iterate through each list converting the tuples to the list.

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course




# Python3 code to demonstrate
# convert list of tuples to list of list
# using list comprehension
  
# initializing list 
test_list = [(1, 2), (3, 4), (5, 6)]
  
# printing original list 
print("The original list of tuples : " + str(test_list))
  
# using list comprehension
# convert list of tuples to list of list
res = [list(ele) for ele in test_list]
  
# print result
print("The converted list of list : " + str(res))
Output :



The original list of tuples : [(1, 2), (3, 4), (5, 6)]
The converted list of list : [[1, 2], [3, 4], [5, 6]]

 

Method #2 : Using map() + list
We can use the combination of map function and list operator to perform this particular task. The map function binds each tuple and converts it into list.




# Python3 code to demonstrate
# convert list of tuples to list of list
# using map() + list
  
# initializing list 
test_list = [(1, 2), (3, 4), (5, 6)]
  
# printing original list 
print("The original list of tuples : " + str(test_list))
  
# using map() + list
# convert list of tuples to list of list
res = list(map(list, test_list))
  
# print result
print("The converted list of list : " + str(res))
Output :
The original list of tuples : [(1, 2), (3, 4), (5, 6)]
The converted list of list : [[1, 2], [3, 4], [5, 6]]



My Personal Notes arrow_drop_up

Start Your Coding Journey Now!