def find_terms(words, max_words_per_term):
    if len(words) == 0:
        return []
return [' '.join(words[:i + 1]) for i in range(min(len(words),
    max_words_per_term))] + find_terms(words[1:], max_words_per_term)
doc = 'a b c d e f'
words = doc.split(None)
for term in find_terms(words, 3):
    pass
How do I generate multi-word terms recursively?