我有两个文本文件d.txt和phrase.txt,其中d.txt包含段落文本,而phrase.txt包含多个单词短语,例如“最先进的技术”,“反生产力”,“舰队动态”等,这些短语在下面的链接中可以找到:
https://en.wikipedia.org/wiki/List_of_buzzwords
如果在phrase.txt中找到匹配的短语,我需要为其颜色着色,以便在d.txt中进行标识
迄今为止的尝试:
phrases = open("phrase.txt").readlines()
words = open("d.txt").read()
for phrase in phrases:
all_words_found = False
phrase_words = phrase.lower().split(" ")
for word in phrase_words:
if word in words:
all_words_found = True
break
if all_words_found:
print (phrase)
请帮忙!
谢谢帮助: