【发布时间】:2021-03-11 07:08:19
【问题描述】:
我需要在不使用正则表达式或任何导入模块的情况下对句子进行标记,但使用内置的 split() 函数。该函数应将文本作为输入,并返回一个包含文本中句子的列表,由“?”、“!”分隔和 '。' 一个例子是:
>>> t = "Are you out of your mind? I can't believe it! I'm so disappointed."
>>> get_sentences(t)
['Are you out of your mind', 'I can't believe it', 'I'm so disappointed']
这是我目前的工作:
def get_sentences(text):
l1 = text.split('.')
for l2 in l1:
l2 = l2.split('!')
for l3 in l2:
l3 = l3.split('?')
return l1
有什么帮助吗?
【问题讨论】:
-
发布的代码无效(缩进错误)。
-
您的代码以何种方式无法回答您要解决的问题?为什么你认为它应该?
标签: python python-3.x string split