code: def _ngrams(segment, n):
      
      ngram_counts = Counter()
      for i in range(0, len(segment) - n + 1):
          ngram = tuple(segment[i:i + n])
          ngram_counts[ngram] += 1
      return ngram_counts
docs: Extracts n-grams from an input segment.
  
      Parameters
      ----------
      segment: list
          Text segment from which n-grams will be extracted.
      n: int
          Order of n-gram.
  
      Returns
      -------
      ngram_counts: Counter
          Contain all the nth n-grams in segment with a count of how many times each n-gram occurred.