神剑山庄资源网 Design By www.hcban.com

如下所示:

#!/usr/bin/env python
#_*_ coding:utf-8 _*_
name = ['hello', 'world', 'a', 'b', 'c', 1, 2, 3, 'hello', 'world', 'a', 'b', 'c', 1, 2, 3]
first_pos = 0
for i in range(name.count(2)):
 new_list = name[first_pos:]
 next_pos = new_list.index(2) + 1
 print 'find ', first_pos + new_list.index(2)
 first_pos += next_pos

note:查找出列表中所有的某个元素

以上这篇Python 查找list中的某个元素的所有的下标方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

标签:
python,list元素下标

神剑山庄资源网 Design By www.hcban.com
神剑山庄资源网 免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
神剑山庄资源网 Design By www.hcban.com

评论“Python 查找list中的某个元素的所有的下标方法”

暂无Python 查找list中的某个元素的所有的下标方法的评论...