title: Sum and divide elements of a RDD in pyspark
body: <p>I am trying to sum all the elements of an RDD and then divide it by the number of elements. I was able to solve it but using different lines. However I would like to do it just with a single line using RDD operations.</p>
  <p>The RDD is for example:</p>
  <pre><code>rdd_example = [(eliana,1),(peter,2),(andrew,3),(paul,4),(jhon,5)]
  </code></pre>
  <p>The first step is to extract just numbers using the method map with a lambda:</p>
  <pre><code>numbers = rdd_example.map(lambda x: x[1])
  </code></pre>
  <p>The output is:</p>
  <pre><code>numbers = [1,2,3,4,5]
  </code></pre>
  <p>Then the sum of all the elements, using the method reduce:</p>
  <pre><code>from operator import add
  sum = numbers.reduce(add)
  </code></pre>
  <p>Then to count the elements another variable is created, using the method count:</p>
  <pre><code>number_elem = rdd_example.count()
  </code></pre>
  <p>Then a division is done to obtain the result:</p>
  <pre><code>result = sum/number_elem 
  </code></pre>
  <p>I would like to do all of it using just a single line, with a single variable.</p>