title: Spark get collection sorted by value
body: <p>I was trying this tutorial <a href="http://spark.apache.org/docs/latest/quick-start.html" rel="noreferrer">http://spark.apache.org/docs/latest/quick-start.html</a>
  I first created a collection from a file</p>
  
  <pre><code>textFile = sc.textFile("README.md")
  </code></pre>
  
  <p>Then I tried a command to cound the words:</p>
  
  <pre><code>wordCounts = textFile.flatMap(lambda line: line.split()).map(lambda word: (word, 1)).reduceByKey(lambda a, b: a+b)
  </code></pre>
  
  <p>To print the collection:</p>
  
  <pre><code> wordCounts.collect()
  </code></pre>
  
  <p>I found how to sort it by word using the command sortByKey. I was wondering how it could be possible to do the same thing for sorting by the value, that in this case in the number that a word occur in the document.</p>