title: N_gram frequency python NTLK
body: <p>I want to write a function that returns the frequency of each element in the n-gram of a given text.
  Help please.
  I did this code fo counting frequency of 2-gram</p>
  
  <p>code:</p>
  
  <pre><code> from nltk import FreqDist
   from nltk.util import ngrams    
   def compute_freq():
       textfile = "please write a function"
       bigramfdist = FreqDist()
       threeramfdist = FreqDist()
       for line in textfile:
           if len(line) &gt; 1:
               tokens = line.strip().split(' ')
               bigrams = ngrams(tokens, 2)
               bigramfdist.update(bigrams)
        return bigramfdist
    bigramfdist = compute_freq()
  </code></pre>