for-loop over tuple in Python: ValueError
<p>I have a tuple of arrays like the following:</p>

<pre><code>z = (array( [ [1], [2], [3]] ),
     array( [[10],[11],[12]] )
    )
</code></pre>

<p>I want to iterate over them with a simple for loop using two variables:</p>

<pre><code>for x, y in z:
    print("it worked")
    self.doStuff(x, y)
</code></pre>

<p>... but it throws the error:</p>

<pre><code>ValueError: too many values to unpack (expected 2)
</code></pre>

<p>I have googled this error. Many seem to suggest the .split() method or .items(). I'm not really sure, where to add those, since the don't belong to tuples. How can I execute this for-loop properly? Thanks for your help.</p>

<p>Reading the other answer it might be that I misunderstood what you want. </p>

<p>You can also use</p>

<pre><code>for x,y in zip(*z):
</code></pre>

<p>to unzip the z tuple.</p>

<p>The output then is:</p>

<pre><code>it worked
[1] [10]
it worked
[2] [11]
it worked
[3] [12]
</code></pre>

python for-loop