Multi-variable for loop with a tuple and a array
<pre><code>Cols = [(10,11),(8,9),(6,7),(4,5),(2,3),(0,1)]
Index = [1,2,3,4,5,6]
Temp = ['RT','85C','125C','175C','220C','260C']


for i,c,t in Index, Cols, Temp:
    print(i,c,t)
</code></pre>

<p>I wish to have i as a tuple, c as an integer and t as a string. When i try the above I keep getting a: </p>

<p><strong>ValueError: too many values to unpack (expected 3)</strong></p>

<p>So I tried following as suggested by other solutions:</p>

<pre><code>x = [[(10,11),(8,9),(6,7),(4,5),(2,3),(0,1)], [1,2,3,4,5,6], ['RT','85C','125C','175C','220C','260C']]

for c,i,t in x:
    print(i,c,t)
</code></pre>

<p>But got the same error as well. Here is what I wish to obtain is:</p>

<pre><code>First loop:
i = 1
c = (10,11)
t = 'RT'

Second loop:
i = 2
c = (8,9)
t = '85C'
.
.
.
.
</code></pre>

<p>Basically the for statement iterates over the contents, one by one, so in each iteration, one value is available.</p>

<p>When using</p>

<pre><code>    for i,c,t in Index, Cols, Temp: 
</code></pre>

<p>you are trying to unpack one value into three variables that's why your are getting <strong>Too many values to unpack ValueError</strong>.since you seem to want to use three different list for a single iteration, there exists a function zip(),izip() and izip_longest() which can be used for this purpose.</p>

<p>zip() returns a list of tuples where the i-th tuple contains the i-th element from each of the list passed as argument to zip(). 
The returned list is truncated in length to the length of the list passed.</p>

<pre><code>    for i,c,t in zip(Index, Cols, Temp):
        print i,c,t
</code></pre>

<p>izip() works same as zip() but it returns an iterator and can be traversed once and they are fast as compared to zip() for single traversal.</p>

<pre><code>    from itertools import izip
    for i,c,t in izip(Index, Cols, Temp):
          print i,c,t
</code></pre>

<p>izip_longest() works same as both zip() and izip() but its helpful when If the iterables are of uneven length, missing values are None by default but can be updated as per requirement.</p>

<pre><code>    from itertools import izip_longest
    for i,c,t in izip_longest(Index, Cols, Temp,fillvalue= 0):
      print i,c,t
</code></pre>

<p>The fillvalue argument is the missing value i.e. 0, if the iterables are of uneven length.</p>

<p>Hope it helps. :)          </p>

python python-3.x jupyter-notebook