【转载】python 获得所有重复元素的索引

借鉴:

https://www.jb51.net/article/162865.htm

 

代码:

 

a = [0, 0 ,1,2,3,1,None]
sameIndex = [i for i,x in enumerate(a) if x in a[:i]]
print(sameIndex)

结果:
[1, 5]

 

你可能感兴趣的:(Python,python)