by haikuginger · 8y ago · 0 comments
tags = list(set(descr.split()) & categories)
The following would also work: tags = [x for x in descr.split() if x in categories]
[1]https://gist.github.com/28mm/9820bd8b6eb27555efe9d6f46dd95a8...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)]