title: python count the number of words in the list of strings
body: <p>consider</p>
  <pre><code>doc = [&quot;i am a fellow student&quot;, &quot;we both are the good student&quot;, &quot;a student works hard&quot;]
  </code></pre>
  <p>I have this as input I just wanted to print the number of times each word in the whole list occurs:</p>
  <p>For example student occurs 3 times so
  <strong>expected output</strong> student=3, a=2,etc</p>
  <p>I was able to print the unique words in the doc, but not able to print the occurrences. Here is the function i used:</p>
  <pre><code>def fit(doc):    
      unique_words = set() 
      if isinstance(dataset, (list,)):
          for row in dataset:
              for word in row.split(&quot; &quot;): 
                  if len(word) &lt; 2:
                      continue
                  unique_words.add(word)
          unique_words = sorted(list(unique_words))
          return (unique_words)
  doc=fit(docs)
  
  print(doc)
  
  ['am', 'are', 'both', 'fellow', 'good', 'hard', 'student', 'the', 'we', 'works']
  </code></pre>
  <p>I got this as output I just want the number of occurrences of the unique_words. How do i do this please?</p>