我有一个功能,当前可以搜索文本以查看其中是否提到了我的任何关键字。我想增强此功能以返回找到的关键字以及识别后的 25 个单词。我的代码如下,但由于“单词”未被识别而无法工作:
def searching(text):
key_words = ["address","home", "location", "domicile"]
if any(word in text for word in key_words):
statement = text[text.find(word) + 1:].split()[0:20]
my_return = " ".join(statement)
return my_return
else:
return "No result"
text = I have a pretty good living situation. I am very thankful for my home located in Massachusetts.
我希望我的函数返回“位于马萨诸塞州的家”,但我收到错误。
NameError: name 'word' is not defined
有任何想法吗?
素胚勾勒不出你
相关分类