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")
添加回答
舉報