How to unzip a list of tuples in Python

Unzipping a list of tuples returns a new list of tuples where each tuple contains the corresponding elements from each original tuple. Unzipping [(“a”, 1), (“b”, 2)] returns [(“a”, “b”), (1, 2)].

Solution for How to unzip a list of tuples in Python : You can use zip() with the * operator to unzip a list of tuples Call zip(*iterable) with the zipped list as iterable to return a zip object. Call list(iterable) with the zip object as iterable to return the list of unzipped tuples.

Further Reading:

Use * to pass elements in a list as arguments to a function. Read more about the * operator here.


how-to-unzip-a-list-of-tuples-in-python