title: How to resolve value error in nested for loops with dictionary
body: <p>I'm new to using Python. I'm adding constraints in an optimization problem where parameters and data inputs are stored in dictionaries. The dictionary mydict_supply has three keys, (k,i,g). The list of keys for mydict_capacitya (arc) has four keys (k,i,j,g). I'm getting a value error for the expected number to unpack that I'm not sure where it's coming from. Relevant code pasted below:</p>
  <pre><code># Import libraries
  from gurobipy import *
  import csv
  from math import *
  import numpy as np
  from random import *
  import time
  # Define Sets and Parameters
  start = time.time()
  # Time set
  timep = list()
  Time = 20 
  for t in range(1, Time + 1):
      timep.append(t)
  
  # amount of supply node
      supply = open('C:/Users/Emma/Documents/2021-2022/Thesis/Data/supply.csv', 'r', encoding='utf-8-sig')
      csv_supply = csv.reader(supply)
      mydict_supply = {}
      for row in csv_supply:
          key_start = row[0:2]
          for index, item in enumerate(row[2:21], 1):
              key = tuple(key_start + [index])
              mydict_supply[key] = item   
      #print(mydict_supply)
  snode = list(mydict_supply.keys()) 
  supply = mydict_supply
  snode = tuplelist(snode)
  
  # arc capacity
  capacitya = open('C:/Users/Emma/Documents/2021-2022/Thesis/Data/arcs.csv', 'r', encoding='utf-8-sig')
  csv_capacitya = csv.reader(capacitya)
  mydict_capacitya = {}
  for row in csv_capacitya:
      key_start = row[0:3]
      for index, item in enumerate(row[3:23], 1):
          key = tuple(key_start + [index])
          mydict_capacitya[key] = item   
  arc = list(mydict_capacitya.keys())
  capacitya = mydict_capacitya
  arc = tuplelist(arc)
  
  
  def RL(whyno, Zedno):
  
      recovery = Model()
      # recovery.setParam('OutputFlag', False)
  
      # Definition of decision variables
  
      O = recovery.addVars(dnode, timep, vtype=GRB.INTEGER, name=&quot;O&quot;)
      X = recovery.addVars(arc, timep, name=&quot;X&quot;)
      Zn = recovery.addVars(attnode, vtype=GRB.BINARY, name=&quot;Zn&quot;)
      Yn = recovery.addVars(attnode, vtype=GRB.BINARY, name=&quot;Yn&quot;)
      Fn = recovery.addVars(attnode,vtype=GRB.BINARY, name=&quot;Fn&quot;)
      An = recovery.addVars(attnode, vtype=GRB.BINARY, name=&quot;An&quot;)
      Apno = recovery.addVars(Crewone, attnode, timep, vtype=GRB.BINARY, name=&quot;Apno&quot;)
      Apntw = recovery.addVars(Crewtwo, attnode, timep, vtype=GRB.BINARY, name=&quot;Apntw&quot;)
      Bn = recovery.addVars(attnode, timep, vtype=GRB.BINARY, name=&quot;Bn&quot;)
  
      # (19)
      for k,i,g in snode:
          for t in timep:
              for c in counter:
                  recoveryd.addConstr(
                  (quicksum(X[k,i, j,g, t,c] for k,i, j in arc.select(k,i,'*',g)) - quicksum(X[k,j, i,g, t,c] for k,j, i in arc.select(k,'*',i,g)) &lt;= mydict_supply[(k,i,g)]),
              name=&quot;19&quot;)
  </code></pre>
  <p>Error:</p>
  <pre><code>&lt;ipython-input-152-d51b2cbee192&gt; in RLD(Zednd)
       71             for c in counter:
       72                 recoveryd.addConstr(
  ---&gt; 73                 (quicksum(X[k,i, j,g, t,c] for k,i, j in arc.select(k,i,'*',g)) - quicksum(X[k,j, i,g, t,c] for k,j, i in arc.select(k,'*',i,g)) &lt;= mydict_supply[(k,i,g)]),
       74                 name=&quot;19&quot;)
  
  src\gurobipy\gurobi.pxi in gurobipy.quicksum()
  
  &lt;ipython-input-152-d51b2cbee192&gt; in &lt;genexpr&gt;(.0)
       71             for c in counter:
       72                 recoveryd.addConstr(
  ---&gt; 73                 (quicksum(X[k,i, j,g, t,c] for k,i, j in arc.select(k,i,'*',g)) - quicksum(X[k,j, i,g, t,c] for k,j, i in arc.select(k,'*',i,g)) &lt;= mydict_supply[(k,i,g)]),
       74                 name=&quot;19&quot;)
  
  ValueError: too many values to unpack (expected 3)
  </code></pre>
  <p>Edit : What this represents mathematically is that the amount of &quot;g&quot; shipped on (i,j) on network k at time t minus the amount of &quot;g&quot; on (j,i) (so going the other way) must be less than the supply of &quot;g&quot; at point i on network k.</p>
  <pre><code>arc.select() returns 
      &lt;gurobi.tuplelist (32340 tuples, 4 values each):
       ( 1 , 1    , 1238 , 1  )
       ( 1 , 1    , 1238 , 2  )
       ( 1 , 1    , 1238 , 3  )
       ( 1 , 1    , 1238 , 4  )
       ( 1 , 1    , 1238 , 5  )
       ( 1 , 1    , 1238 , 6  )
       ( 1 , 1    , 1238 , 7  )
  </code></pre>