N-gram Dictionary
Write a function get_ngrams
to take in a word (string) and return a dictionary of n-grams and their frequency in the given string.
Example 1:
Input:
string = 'banana'
n=2
Output:
output = {'ba':1, 'an':2, 'na':2}
Example 2:
Input:
string = 'banana'
n=3
Output:
output = {'ban':1, 'ana':2, 'nan':1}
Next question: Compute Variance.....
Loading editor