# -*- 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_listif __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
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态