我有两条线。你知道吗
str = "This is an example sentence, it is for demonstration only"
k = "example sentence"
#k可能包含一个或多个单词
我想在str
中找到k
,但我需要单词索引。
我分裂了str
splitted_str = str.split()
print(splitted_str)
['This', 'is', 'an', 'example', 'sentence,', 'it', 'is', 'for', 'demonstration', 'only']
如果我匹配splitted_str
中的k
,那么函数应该给我example
的索引3和sentence
的索引4。你知道吗
re.search().start()
它只给出字符串起始索引。你知道吗
请建议。你知道吗
提前谢谢。你知道吗
试着把你短语上的句子分开,然后数一数前面的单词。你知道吗
相关问题 更多 >
编程相关推荐