list = [1,2,3,3,2,1]
list.index(1) # 只能获得首个1的索引值

如果要获得所有该元素的索引值

import numpy as np
arr = np.array(list)
index = np.where(arr==1)
index[0]

然后才能用

for i in index[0]:
    print(i)

获得一个list中某元素的索引值

 

相关文章: