Write a Python program to unzip a list of tuples into individual lists


The program is written in Python and it declares a list l with three elements, each of which is a tuple of two integers. The program then uses the zip function to transpose the elements of the list l. The zip function takes the elements of each tuple in the list as separate arguments, effectively transposing the rows and columns of the list. The * operator is used to unpack the list of tuples l into separate positional arguments. The output of zip(*l) is a list of tuples, where each tuple contains the elements from the corresponding positions in the original tuples of the list l. Finally, the list function is used to convert the output of the zip function to a list and the result is passed as an argument to the print function. The transposed list is printed on the console.

Source Code

#create a tuple
l = [(10,30), (60,90), (20,50)]
print(list(zip(*l)))
 

Output

[(10, 60, 20), (30, 90, 50)]


Example Programs