按一定百分比拆分文本字符串



我需要从某个分数中分割一个文本。例如,50%文本后的第一个点。示例:

a = 'Hello this text. It is a reference. But I like it very much, I would like to share with you everything I know. Goodbye friends.'

如果我想从50%后的第一个点开始划分文本,我会得到:

'Goodbye friends.'

我怎么能得到这个结果?

a = 'Hello this text. It is a reference. But I like it very much, I would like to share with you everything I know. Goodbye friends.'
#first we get the index of the string to the half, using len function to get the total len,
#then that len is divided by 2, and using :len(a) we take the 
#the last place of the string
b = a[int(len(a) / 2):len(a)]
#with find function save in a variable the index of the first dot
#in the string saved on variable b
c = b.find(".")
#In a new variable taken the new string, using square 
#brackets we take the index of the first dot saved on variable c, and then using len 
#function we indicate the last place of the string 
d = b[c:len(b)]
print(d)

最新更新