下面是使用 Python 代码从文本文档中提取含有指定关键词的句子的示例:
# 首先,需要打开文件并读取文本内容
with open('world.txt', 'r') as f:
text = f.read()
# 然后,将文本分割为句子
sentences = text.split('.')
# 定义关键词
keyword = 'world'
# 遍历句子,检查是否含有关键词
for sentence in sentences:
if keyword in sentence:
print(sentence)
在这个示例中,我们使用