title: how can I iterate through list of list in "pyspark" for a specific result
body: <p>I am new to PySpark, I am trying to understand how I can do this. Any help appreciated.</p>
  
  <p>I have this RDD for example :</p>
  
  <pre><code>[[u'merit', u'release', u'appearance'], [u'www.bonsai.wbff.org'], [u'whitepages.com'], [u'the', u'childs', u'wonderland', u'company'], [u'lottery']]
  </code></pre>
  
  <p>I try to have :</p>
  
  <pre><code>[[(u'merit',1), (u'release',1), (u'appearance',1)], [(u'www.bonsai.wbff.org',1)], [(u'whitepages.com',1)], [(u'the',1), (u'childs',1), (u'wonderland',1), (u'company',1)], [(u'lottery',1)]] 
  </code></pre>
  
  <p>But all I've tried, it gets me either this result :</p>
  
  <pre><code>[[u'merit', u'release', u'appearance',1], [u'www.bonsai.wbff.org',1], [u'whitepages.com',1], [u'the', u'childs', u'wonderland', u'company',1], [u'lottery',1]]
  </code></pre>
  
  <p>or these errors:</p>
  
  <ul>
  <li><code>TypeError: 'PipelinedRDD' object is not iterable</code></li>
  <li><code>AttributeError: 'list' object has no attribute 'foreach'</code> - or <code>split</code>, <code>take</code>, etc. </li>
  </ul>
  
  <p>I tried this :</p>
  
  <pre><code>rdd1=rdd.map(lambda r : (r,1))  
  </code></pre>
  
  <p>I have the first result :  </p>
  
  <pre><code>[u'merit', u'release', u'appearance',1], [u'www.bonsai.wbff.org',1], [u'whitepages.com',1], [u'the', u'childs', u'wonderland', u'company',1], [u'lottery',1]]
  
  rdd1=rdd.map(lambda r : (r[:][0],1))  
  </code></pre>
  
  <p>It gets just the first word in each line, it's not what I want</p>
  
  <pre><code>for row in rdd.collect() : row.foreach(lambda x : (x,1)) 
  # AttributeError: 'list' object has no attribute 'foreach'
  </code></pre>
  
  
  
  <pre><code>rdd3.take(100).foreach( lambda a : (a.foreach( lambda e : print(e,1)))) 
  # AttributeError: 'list' object has no attribute 'foreach'
  </code></pre>