by 28mm · 8y ago · 0 comments
If memory serves, the reason it doesn’t first split the description on white space is that some categories contain whitespace, and would never match.
Thanks!
def get_all_phrases(descr):
words = descr.split()
if len(words) == 1:
return words
phrases = []
for i in range(2, len(words) + 1):
phrases += get_phrases_of_len(i, words)
return words + phrases
def get_phrases_of_len(length, words):
return [' '.join(words[i:i+length]) for i in range((len(words) - length) + 1)]