您的位置:首页 > 编程语言 > Python开发

解决python list列表查找重复值的下标值问题

2018-02-07 20:52 441 查看
#!/usr/bin/env python
# !_*_ coding:utf-8 _*_

"""
@version: python2.7
@license: Apache Licence
@contact: longzinziyan@gmail.com
@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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  list 列表 python index 查找