Convert List of Tuples to List of Lists in Python (3 Examples)

 

Hi! This tutorial will show you 3 examples of how to transform a list of tuples to a list of lists in the Python programming language.

First, though, here is a quick overview of this tutorial:

Let’s get right into the Python code!

 

Create Sample List of Tuples

Here, we will create the sample list of tuples that will be turned into a list of lists in this tutorial. So, in your preferred Python programming IDE, run the line of code below to create the sample list of tuples containing integer pairs.

tuple_list = [(1, 2), (3, 4), (5, 6)]

 

Example 1: Transform List of Tuples to List of Lists with map() Function

In this first example, we will use Python’s map() function to turn the list of tuples to a list of lists.

list_list = list(map(list, tuple_list))
print(list_list)
 
# [[1, 2], [3, 4], [5, 6]]
 
 
print(type(list_list))
 
# <class 'list'>

In the above code, we used the map() function to iteratively apply the list() constructor to the tuples in the original list of tuples tuple_list, and a list of lists is returned as the output.
 

Example 2: Transform List of Tuples to List of Lists with For Loop

In this next example, we will use a for loop to transform the list of tuples to a list of lists.

list_list = []
for t in tuple_list:
    list_list.append(list(t))
print(list_list)
 
# [[1, 2], [3, 4], [5, 6]]
 
 
print(type(list_list))
 
# <class 'list'>

In the above example, we used a for loop to iterate over the tuples in the original list of tuples tuple_list and converted each tuple to a list using the list() constructor, and appended the resulting list to a new list list_list.

 

Example 3: Transform List of Tuples to List of Lists with List Comprehension

In this third and final example, we will use list comprehension to convert the list of tuples to a list of lists.

list_list = [list(t) for t in tuple_list]
print(list_list)
 
# [[1, 2], [3, 4], [5, 6]]
 
 
print(type(list_list))
 
# <class 'list'>

In the code above, we used a list comprehension to iterate through the tuples in the original list, then converted each tuple into a list, using the list() constructor, and then appended the resulting lists to a new list. It works exactly like the for loop in the previous example; just more concise.

With that, we have demonstrated 3 simple ways to turn a list of tuples into a list of lists in Python. I hope you found this tutorial helpful!
 

Video, Further Resources & Summary

Do you need more explanations on how to turn a list of tuples into a list of lists in Python? Then you should have a look at the following YouTube video of the Statistics Globe YouTube channel.

In the video, we explain in some more detail how to turn a list of tuples into a list of lists in Python.

 

The YouTube video will be added soon.

 

Furthermore, I encourage you to check out other interesting Python list tutorials on Statistics Globe, starting with these ones:

This post has shown how to turn a list of tuples into a list of lists in Python. In case you have further questions, you may leave a comment below.

 

R & Python Expert Ifeanyi Idiaye

This page was created in collaboration with Ifeanyi Idiaye. You might check out Ifeanyi’s personal author page to read more about his academic background and the other articles he has written for the Statistics Globe website.

 

Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.


Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Top