How to extract character ngram from sentences? - python
The following word2ngrams function extracts character 3grams from a word: >>> x = 'foobar' >>> n = 3 >>> [x[i:i+n] for i in range(len(x)-n+1)] ['foo', 'oob', 'oba', 'bar'] This post shows the character ngrams extraction for a single word, Quick implementation of character n-grams using python . But what if i have sentences and i want to extract the character ngrams, is there a faster method other than iteratively call the word2ngram() ? What will be the regex version of achieving the same word2ngram and sent2ngram output? would it be faster? I've tried: import string, random, time from