easy +10 pts

Unzip pairs into two lists

Transform a list of pairs into a pair of lists using Python's zip and unpacking.

Write a function `unzip_pairs(pairs)` that takes a list of tuples (or lists) of length 2 and returns a tuple of two lists: the first list contains all first elements in order, and the second list contains all second elements in order. For example, `unzip_pairs([(1, 'a'), (2, 'b'), (3, 'c')])` should return `([1, 2, 3], ['a', 'b', 'c'])`.

Constraints

The input list will contain between 0 and 1000 pairs. Each pair is a tuple or list of exactly two elements. Elements can be of any type (including mixed types within a pair). The output must preserve the original order of the pairs.

Example

>>> unzip_pairs([(1, 'a'), (2, 'b'), (3, 'c')])
([1, 2, 3], ['a', 'b', 'c'])
>>> unzip_pairs([])
([], [])
>>> unzip_pairs([[0, 1], [2, 3], [4, 5]])
([0, 2, 4], [1, 3, 5])
10 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Consider using `zip(*pairs)` to unpack the list into separate sequences.
After calling `zip(*pairs)`, convert each resulting tuple to a list.
Remember that `zip(*[])` gives an empty iterator; handle that case correctly.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.