如下所示:
#!/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 = 0for 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:查找出列表中所有的某個(gè)元素
以上這篇Python 查找list中的某個(gè)元素的所有的下標(biāo)方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持武林站長站。
新聞熱點(diǎn)
疑難解答
圖片精選