title: Lambda function causing TypeError: 'int' object is not iterable
body: <p>I just started learning Python. I'm using an API to build an IDFs model,however I'm facing some errors with the lambda functions which I cannot resolve.
  This the class that generates the IDF:</p>
  
  <pre><code>class Idfs(DocumentFrequencies, Model):
  
      def build(self, corpus):
          log.info('Counting documents in corpus...')
          N = float(corpus.count())
          dfs = super(Idfs, self).build(corpus)
  
          log.info('Building idf model: N=%i', N)
          return dfs\
             .map(lambda (term, (df,rank)): (term, df))\  
             .mapValues(lambda df: math.log(N/df))
  
      @staticmethod
      def format_item((term, idf)):
          return {
          '_id': term,
          'idf': idf,
          }
  </code></pre>
  
  <p>And the this is the class that count the DF:</p>
  
  <pre><code>class DocumentFrequencies(ModelBuilder):
  
      def __init__(self, lowercase=False, max_ngram=1, min_df=2):
          self.lowercase = lowercase
          self.max_ngram = max_ngram
          self.min_df = min_df
  
      def build(self, docs):
          m = docs.map(lambda d: d['text'])
          if self.lowercase:
              m = m.map(lambda text: text.lower())
  
          return m\
              .flatMap(lambda text: set(ngrams(text, self.max_ngram)))\
              .map(lambda t: (t, 1))\
              .reduceByKey(add)\
              .filter(lambda (k,v): v &gt; self.min_df)
  </code></pre>
  
  <p>The error appears in this line <code>.map(lambda (term, (df, rank)): (term, df))\</code> and this is the error message : </p>
  
  <pre><code>TypeError: 'int' object is not iterable
  </code></pre>
  
  <p>This is what I get when I call <code>DocumentFrequencies.collect()</code>:</p>
  
  <pre><code>Out[5]:                                                                         
  [(u'fawn', 3),
   (u'1,800', 31),
   (u'clotted', 3),
   (u'comically', 11),
   (u'Adjusting', 3),
   (u'O(log', 6),
   (u'unnecessarily', 15),
   (u'evangelical', 53),
   (u'naturopathic', 3),
   (u'grenadiers', 4),
   (u'stipulate', 4),
   (u'Vikrant', 3),
   (u'fractal', 18),
  </code></pre>
  
  <p>I dont know which argument exactly is causing the error. I'm using python 2.7, 8 GB 1600 MHz DDR with 2 cores. These are the pyspark configs:</p>
  
  <pre><code>conf = pyspark.SparkConf().setAll([('spark.executor.memory', '8g'),('spark.driver.memory','8g'),('spark.network.timeout','100000000s'),('spark.executor.heartbeatInterval','10000000s'),('spark.driver.maxResultSize','8g'),('spark.driver.cores','2')])
  </code></pre>
  
  <p>Thanks in advance,</p>