问题:查找列表中指定的值的所有元素
使用list的index方法
1 def find_index(src, key): 2 start_pos = 0 3 for i in range(src.count(key)): 4 if start_pos == 0: 5 start_pos = src.index(key) 6 else: 7 start_pos = src.index(key, start_pos+1) 8 print(start_pos) 9 10 if __name__ == '__main__': 11 src = [1, 2, 3, 5, 2, 7, 2, 0, 3, 2] 12 key = -6 13 find_index(src, key)