我正在制作一个正在浏览很多评论的漫游器,并且我想找到任何以“I'm
”或“I am
”开头的句子。这是一个示例注释(有两个句子,我想提取)。找到并提取一段包含python中的关键字的字符串
"Oh, in that case. I'm sorry. I'm sure everyone's day will come, it's just a matter of time."
这是我到目前为止的功能。
keywords = ["i'm ","im ","i am "]
def get_quote(comments):
quotes = []
for comment in comments:
isMatch = any(string in comment.text.lower() for string in keywords)
if isMatch:
我怎样才能找到其中的句子开始和结束,所以我可以把它.append到列表quotes
?
你如何判断句子的结尾? – Kasramvd
查看'str'实例的'index'和'find'方法。另一个解决方案是使用正则表达式。看看这个[示例](http://stackoverflow.com/questions/8459412/find-start-and-end-positions-of-all-occurrences-within-a-string-in-python#8459451)。 – kikocorreoso
@Kasramvd A'''我觉得最好。 – MadManoloz