Showing posts with label unzip. Show all posts
Showing posts with label unzip. Show all posts

Tuesday, February 24, 2009

Unzip a Python list

Suppose that you have a list with tuples as the member.
>>> test = [('x',1), ('y',2), ('z',3)]
We can unzip the list by using zip() in conjunction with the * operator.
>>> a, b = zip(*test)
>>> a
('x', 'y', 'z')
>>> b
(1, 2, 3)