text = "The cat ran. I am Sam. Whoop dee doo."
output = get_sentence("am")
应该产生 -->"I am Sam."
芜湖不芜
浏览 210回答 3
3回答
至尊宝的传说
您可以使用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']
将字符串拆分为句子,然后在每个句子中搜索该短语text = text.split('. ')for s in text: if searchWord in s: return s + "." return "Search word not found"
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")