A Transpose/Unzip Function in Python (inverse of zip)
<p>I have a list of 2-item tuples and I'd like to convert them to 2 lists where the first contains the first item in each tuple and the second list holds the second item.</p>

<p><strong>For example:</strong></p>

<pre><code>original = [('a', 1), ('b', 2), ('c', 3), ('d', 4)]
# and I want to become...
result = (['a', 'b', 'c', 'd'], [1, 2, 3, 4])
</code></pre>

<p>Is there a builtin function that does that?</p>

<p><a href="http://docs.python.org/library/functions.html#zip"><code>zip</code></a> is its own inverse! Provided you use the special * operator.</p>

<pre><code>&gt;&gt;&gt; zip(*[('a', 1), ('b', 2), ('c', 3), ('d', 4)])
[('a', 'b', 'c', 'd'), (1, 2, 3, 4)]
</code></pre>

<p>The way this works is by calling <code>zip</code> with the arguments:</p>

<pre><code>zip(('a', 1), ('b', 2), ('c', 3), ('d', 4))
</code></pre>

<p>â¦ except the arguments are passed to <code>zip</code> directly (after being converted to a tuple), so there's no need to worry about the number of arguments getting too big.</p>
