def remove_after_sym(s, sym):
# Find first word
first = s.strip().split(' ')[0]
# Split the string using the symbol
l = []
s = s.strip().split(sym)
# Split words by space in each sentence
for a in s:
x = a.strip().split(' ')
del x[0]
l.append(x)
# Join words in each sentence
for i in range(len(l)):
l[i] = ' '.join(l[i])
# Combine sentences
final = first + ' ' + ' '.join(l)
final = final.strip() + '.'
return final
下面是一种不用regex的方法,使用
del
如您所述:这里,sym是一个
str
(单个字符)。你知道吗另外,我也非常随意地使用了“句”这个词,比如在你的例子中,
sym
是一个点。但这里的句子实际上是指被你想要的符号打断的部分字符串。你知道吗这是它的输出。你知道吗
相关问题 更多 >
编程相关推荐