python

Python – Convert list of tuples to list of lists

In this tutorial, we are going to see how to convert a list of tuples to a list of lists in Python. Python provides different types of variables for programmers. We can use data types like int, float, string, list, set… in our applications. When using different types of variables, it may be necessary to convert these to different types.
 

 

How to convert a list of tuples to a list of lists using comprehension list

This can be easily achieved by using the comprehension lists. We simply iterate through each list, turning each tuple into a list.

list_tuple = [(1, 1), (2, 2), (3, 3)] 
# Using comprehension list
list_list = [list(i) for i in list_tuple]
# Print the list
print(list_list)

Output:

[[1, 1], [2, 2], [3, 3]]
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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