import difflib
from nltk.util import ngrams
words = corpus.split(' ')
words_ngrams = []
for n in range(1, 6):
    words_ngrams.extend(' '.join(ngrams(words, n)))
to_delete = []
sim_rate = 0.8
max_matches = 4
for term in terms:
    matches = difflib.get_close_matches(term, words_ngrams, n=max_matches,
        cutoff=sim_rate)
for match in matches:
    to_delete.append((corpus.index(match), len(match)))
How to accurately classify text with a lot of potential values using sckit?