title: Recursively checking for values of a key
body: <p>I am running into following error with below piece of code, basically below is what I am trying to do, below code works fine if there is only one value... if the values are more I get the error "too many values to unpack", how can I modify my code without changing the original goal...</p>
  
  <ol>
  <li>if any of the values is a key with no values remove that line from the input</li>
  <li><p>if any of the values is a key with values, for each value (which is key) recursively check for its values until there are none and remove the duplicate lines...a sample input and output is shown below:</p>
  
  <pre><code>KEY    VALUES
  353311
  344670 
  332807 353314
  338169 334478
  334478 123456 34567
  123456 98670
  34567  11111  
  353314 353311
  348521 350166 350168 350169 350170 
  350166 348521
  350168 348521
  350169 348521
  350170 348521
  
  EXPECTED OUTPUT
  344670
  332807 353314 353311
  338169 334478 123456 34567 98670 11111
  348521 350166 350168 350169 350170  
  </code></pre></li>
  </ol>
  
  <p>Code:-</p>
  
  <pre><code>from collections import OrderedDict
  def main ():
      with open('gerrit_dependencylist.txt') as f:
          dic = OrderedDict()
          seen = set()
          for line in f:
              #print dic,line
              spl = line.split()
              print "SPL"
              print spl
              if len(spl) == 1:
                  key = spl[0]
                  v = ''
              else:
                  print "LINE"
                  print line
                  key, v = spl
              if v in dic and dic[v] == [""]:
                  del dic[v]
              for k1,v1 in dic.items():
                  if key in v1:
                      dic[k1].append(v)
                      break
              else:
                  dic[key] = [v]
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p>OUTPUT:-</p>
  
  <pre><code>LINE
  332807 353314
  
  LINE
  338169 334478
  
  LINE
  334478 123456 34567
  
  Traceback (most recent call last):
    File "tesst.py", line 28, in &lt;module&gt;
      main()
    File "tesst.py", line 18, in main
      key, v = spl
  ValueError: too many values to unpack
  </code></pre>