title: Spark: use reduceByKey instead of groupByKey and mapByValues
body: <p>I have an RDD with duplicates values with the following format:</p>
  
  <pre><code>[ {key1: A}, {key1: A}, {key1: B}, {key1: C}, {key2: B}, {key2: B}, {key2: D}, ..]
  </code></pre>
  
  <p>I would like the new RDD to have the following output and to get ride of duplicates.</p>
  
  <pre><code>[ {key1: [A,B,C]}, {key2: [B,D]}, ..]
  </code></pre>
  
  <p>I have manage to do this with the following code by putting the values in a set to get ride of duplicates.</p>
  
  <pre><code>RDD_unique = RDD_duplicates.groupByKey().mapValues(lambda x: set(x))
  </code></pre>
  
  <p>But I am trying to achieve this more elegantly in 1 command with </p>
  
  <pre><code>RDD_unique = RDD_duplicates.reduceByKey(...)
  </code></pre>
  
  <p>I have not managed to come up with a lambda function that gets me the same result in the reduceByKey function.</p>