I\'m using NLTK to search for n-grams in a corpus but it\'s taking a very long time in some cases. I\'ve noticed calculating n-grams isn\'t an uncommon feature in other pack
For character-level n-grams you could use the following function
def ngrams(text, n): n-=1 return [text[i-n:i+1] for i,char in enumerate(text)][n:]