title: How to count the number of words per line in text file using RDD?
body: <p>Is there a way to count the number of word occurrences for each line of an RDD and not the complete RDD using map and reduce?</p>
  
  <p>For example, if an RDD[String] contains these two lines: </p>
  
  <blockquote>
    <p>Let's have some fun.</p>
    
    <p>To have fun you don't need any plans.</p>
  </blockquote>
  
  <p>then the output should be like a map containing the key value pairs:</p>
  
  <blockquote>
    <p>("Let's",1)<br>
    ("have",1)<br>
    ("some",1)<br>
    ("fun",1)<br></p>
    
    <p>("To",1)<br>("have",1)<br>("fun",1)<br>("you",1)<br>("don't",1)<br>("need",1)<br>("plans",1)</p>
  </blockquote>