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)
If you are new here, you might want to subscribe to the RSS feed or newsletter.

Enter your email address:

Related

This entry was posted in Python and tagged , , , , . Bookmark the permalink.

One Response to Unzip a Python list

  1. Pingback: ?????Python zip??????? - Nine Rivers ????

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>