title: Too many values to unpack in lambda function
body: <p>I just started learning Python. I'm using an API to build a TFIDFs model, however I'm facing some errors with the lambda functions which I cannot resolve. This is part of the class that generates the TFIDFs:</p>
  
  <pre><code>class tfidf(ModelBuilder, Model):
  
      def __init__(self, max_ngram=1, normalize = True):
          self.max_ngram = max_ngram
          self.normalize = normalize
  
      def build(self, mentions, idfs):
          m = mentions\
              .map(lambda (target, (span, text)): (target, text))\  """error is triggered here  """
              .mapValues(lambda v: ngrams(v, self.max_ngram))\
              .flatMap(lambda (target, tokens): (((target, t), 1) for t in tokens))\
              .reduceByKey(add)\
              .map(lambda ((target, token), count): (token, (target, count)))\
              .leftOuterJoin(idfs)\
  </code></pre>
  
  <p>And here is a sample output of the <code>mentions</code> class (which is the input causing the error in <code>tdfidf</code> class):</p>
  
  <pre><code>Out[24]:                                                                        
  [{'_id': u'en.wikipedia.org/wiki/William_Cowper',
    'source': 'en.wikipedia.org/wiki/Beagle',
    'span': (165, 179),
    'text': u'References to the dog appear before the 19th century in works by such writers as William Shakespeare, John Webster, John Dryden, Thomas Tickell, Henry Fielding, and William Cowper, as well as in Alexander Pope\'s translation of Homer\'s "Iliad".'},
   {'_id': u"en.wikipedia.org/wiki/K-Run's_Park_Me_In_First",
    'source': 'en.wikipedia.org/wiki/Beagle',
    'span': (32, 62),
    'text': u" On 12 February 2008, a Beagle, K-Run's Park Me In First (Uno), won the Best In Show category at the Westminster Kennel Club show for the first time in the competition's history."},
  </code></pre>
  
  <p>The error message is:</p>
  
  <pre><code> .map(lambda (target, (span, text)): (target, text))\
  ValueError: too many values to unpack
  </code></pre>
  
  <p>I tried:  <code>.map(lambda ( src, target, span, text) : (target, text))\</code> since I only need the target and text which causes the same error in <code>mentions\</code>.</p>
  
  <p>A simple and a compilable example:</p>
  
  <pre><code>import math
  import numpy
  
  
  Data = [{'_id': '333981',
  
    'source': 'Apple',
  
    'span': (100, 119),
  
    'text': ' It is native to the northern Pacific.'}, {'_id': '27262',
  
    'source': 'Apple',
  
    'span': (4, 20),
  
    'text': ' Apples are yummy.'}]
  
  
  
  m = map(lambda (ID, (span, text)) : (ID, text) , Data)
  
  print(list(m))
  </code></pre>
  
  <p>I'm using python 2.7. Any help or guidance will be much appreciated.</p>
  
  <p>Many thanks,</p>