Python zip - Why do we need to unpack the argument?
<p>I'm trying to understand the need to unpack the arguments using <code>*</code> when the input to <code>zip</code> is a 2D list.  The <a href="https://docs.python.org/3/library/functions.html#zip" rel="nofollow">docs</a> state,</p>

<blockquote>
  <p>[zip] Returns an iterator of tuples, where the i-th tuple contains the i-th element from each of the argument sequences or iterables.</p>
</blockquote>

<p>So, regarding the second <code>print</code> statement below, I expected it to be just like the ones before and after it.  I am having trouble connecting the description of <code>zip</code> to this result.</p>

<p>MWE:                                                                 </p>

<pre><code>x = [1, 2, 3]
y = [4, 5, 6]

print zip(x, y)
print zip([x, y])  # don't understand this result
print zip(*[x, y])
</code></pre>

<p>Result:</p>

<pre><code>[(1, 4), (2, 5), (3, 6)]
[([1, 2, 3],), ([4, 5, 6],)]
[(1, 4), (2, 5), (3, 6)]
</code></pre>

<p>Consider this example:</p>

<pre><code>&gt;&gt;&gt; x = [1, 2, 3]
&gt;&gt;&gt; y = [4, 5, 6]
&gt;&gt;&gt; z = [7, 8, 9]
&gt;&gt;&gt; zip(x,y,z)
[(1, 4, 7), (2, 5, 8), (3, 6, 9)]
&gt;&gt;&gt; zip(x,y)
[(1, 4), (2, 5), (3, 6)]
&gt;&gt;&gt; zip(x)
[(1,), (2,), (3,)]
&gt;&gt;&gt; zip()
[]
</code></pre>

<p>Observe that <code>zip</code> with a single argument (and even with no arguments!) follows the same pattern. It always returns a sequence of tuples, where the tuples (if there are any) have the same number of members as the arguments to <code>zip</code>. Even when there's only one argument to <code>zip</code>.</p>

<p>Now consider the case you're asking about:</p>

<pre><code>zip([x, y])
</code></pre>

<p>This is just <code>zip</code> with one argument! <code>Zip</code> isn't going to try to be clever and poke about inside the elements of the sequence you give it. It doesn't know or care that the elements of the sequence you gave it are themselves sequences. <code>Zip</code> is (thankfully!) simple and predictable. If you give it one argument it returns you a sequence of 1-tuples. In this case those 1-tuples contain a list each, but again, <code>zip</code> doesn't care! They could be strings or numbers or <code>None</code> or anything!</p>

<pre><code>&gt;&gt;&gt; zip([x, y])
[([1, 2, 3],), ([4, 5, 6],)]
&gt;&gt;&gt; zip([x, 'marmalade'])
[([1, 2, 3],), ('marmalade',)]
&gt;&gt;&gt; zip([None, y])
[(None,), ([4, 5, 6],)]
</code></pre>

python