How to get the key value output from RDD in pyspark
<p>Following is the RDD:</p>

<pre><code>[(8, [u'darkness']), (2, [u'in', u'of', u'of', u'of']),
(4, [u'book', u'form', u'void', u'upon', u'face', u'deep', u'upon', u'face'])]
</code></pre>

<p>How do i print the keys and the value length for the above.</p>

<p>The output for above should be:
(key, no of words in the list) </p>

<blockquote>
  <p>(8,1) (2,4) (4,8)</p>
</blockquote>

<p>You can use a <code>map</code> function to create a tuple of the key and number of words in the list:</p>

<pre><code>data = sc.parallelize([(8, [u'darkness']), (2, [u'in', u'of', u'of', u'of']), (4, [u'book', u'form', u'void', u'upon', u'face', u'deep', u'upon', u'face'])])

data.map(lambda x:tuple([x[0],len(x[1])])).collect()
</code></pre>

python pyspark rdd