网络编程
位置:首页>> 网络编程>> Python编程>> Python 查找list中的某个元素的所有的下标方法

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

作者:xuejinliang  发布时间:2022-10-15 21:48:16 

标签:python,list,元素,下标

如下所示:


#!/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:查找出列表中所有的某个元素

来源:https://blog.csdn.net/xuejinliang/article/details/51591951

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com