from typing import Counter


def ngram_counter(list_of_token, n=2):
	"""
	Function for converting a list of ordered tokens into n-grams.
	| Argument
	| | list_of_token: a list of ordered tokens to be processed.
	| 
	| Parameter
	| | n: number of continuous tokens to group
	|
	| Output
	| | dictionary of count of ngrams (type: collections.Counter)
	"""
	if len(list_of_token) < n: raise Exception("Can't get {}-gram from input of length {}".format(n, len(list_of_token)))
	ngram_cnt = Counter([' '.join(list_of_token[index:index+n]) for index in range(len(list_of_token)-n+1)])
	return ngram_cnt