#!/usr/bin/env python # !_*_ coding:utf-8 _*_ """ @version: python2.7 @license: Apache Licence @contact: [email protected] @site: http://blog.csdn.net/dielian520 @software: PyCharm @time: 18-2-7 下午6:21 """ a = [8, 1, 5, 6, 8, 7, 8, 4, 8, 2, 5, 4, 8, 6, 5, 4, 8, 7, 5, 2, 8, 8, 8] temp = 8 flag = 0 list_index = [] for n in range(a.count(temp)): sec = flag flag = a[flag:].index(temp) list_index.append(flag + sec) flag = list_index[-1:][0] + 1 print(list_index)