python如何逆向索引列表,【python 字母索引】找到英文句子里面每个单词最后一个字母的索引

 2023-09-25 阅读 40 评论 0

摘要:# -*- 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(sen
# -*- 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

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://808629.com/100241.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 86后生记录生活 Inc. 保留所有权利。

底部版权信息