Python查询列表内重复值的下标

Python查询列表内重复值的下标

1
2
3
4
5
6
7
8
9
10
11
12
13
#将返回seq内所有值为item项的下标
$ def listDuplicate(seq, item):
startIndex = -1
strIndexs = []
while True:
try:
strIndex = seq.index(item,startIndex+1)
except ValueError:
break
else:
strIndexs.append(strIndex)
startIndex = strIndex
return strIndexs