#!/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:查找出列表中所有的某个元素
#_*_ 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脚本示例,展示了如何遍历列表并查找特定元素的所有出现位置。通过使用简单的for循环和列表索引,该脚本能够有效地定位并打印出指定元素在列表中的每个位置。
2364

被折叠的 条评论
为什么被折叠?



