Skip to main content
 首页 » 编程设计

python之从字符串列表中获取拆分句子的索引

2025年05月04日37txw1958

<分区>

所需的结果要么是一个函数,要么是一种在字符串列表中查找句子位置的方法。

sentence = 'The cat went to the pool yesterday' 
 
structure = ['The cat went,', 'to the pool yesterday.','I wonder if you realize the effect you are having on me. It hurts. A lot.'] 

例如

def findsentence(sentence, list of strings): 
      # do something to get the output, vec of positions to find the sentence in hte string list 
return output 
 
findsentence(sentence, structure) 
> (0,1) # beacuse the phrase is splitted in the list... 

注意!!

挑战在于不能准确地找到句子。看例子,这句话是句子位置0的一部分,结构位置1的一部分。

所以这不是一个简单的字符串操作问题。