版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013421629/article/details/83588567
# -*- coding:utf-8 -*-
sentence="wo ai ni zhong guo"
def find_english_word_last_index(sentence):
"""
:param sentence: 英文句子
:return: 返回英文句子的每个单词最后的字母的索引
"""
last_index_list=[]
for i,j in enumerate(sentence):
print(i,j)
if j==' ':
last_index_list.append(i-1)
last_index_list.append(len(sentence)-1)
print(last_index_list)
return last_index_list
if __name__ == '__main__':
find_english_word_last_index(sentence)
运行结果:
0 w
1 o
2
3 a
4 i
5
6 n
7 i
8
9 z
10 h
11 o
12 n
13 g
14
15 g
16 u
17 o
[1, 4, 7, 13, 17]
Process finished with exit code 0