3 回答
TA贡献1789条经验 获得超10个赞
您可以使用nltk库来标记句子
nltk.download("punkt")
text = "Hello, I am Taksh. Nice to meet you Mr. Panchal.
You scored 82.5 % in test"
nltk.tokenize.sent_tokenize(text)
>> ['Hello, I am Taksh.',
'Nice to meet you Mr. Panchal.',
'You scored 82.5 % in test']
TA贡献1876条经验 获得超5个赞
将字符串拆分为句子,然后在每个句子中搜索该短语
text = text.split('. ')
for s in text:
if searchWord in s:
return s + "."
return "Search word not found"
TA贡献1836条经验 获得超13个赞
text = "The cat ran. I am Sam. Whoop dee doo."
text = text.split('.')
data = input("Enter the String want to search")
for i in text:
if data in i:
print(i )
else:
print("search word is not present")
添加回答
举报