python返回列表中指定内容的索引
import numpy as np
a=[2,10,2,3,4,10,10]
ans = np.where(np.array(a)==10)
print(ans)
结果是:(array([1, 5, 6], dtype=int64),)
就是说,np.where()可以返回同一个元素在不同位置的索引。
a=[2,10,2,3,4,10,10]
ans = a.index(10)
print(ans)
结果是:1
就是说,a.index()返回指定元素第一个位置的索引。