1
我有一个元组列表如下:搜索指数
tupleList = [('a','b'), ('c','d'), ('a','b'), ('a','b'), ('e','f')]
我想找到的('a','b')
指数tupleList。
我尝试以下操作:
idx = np.where(tupleList == ('a','b'))
,但它提供了一个空数组。
希望的输出将是
idx = [0, 2, 3]
列表和元组不支持如NumPy的阵列相同的操作;例如,'tupleList ==('a','b')'不是元素比较。元组列表可能不是最好的数据结构。 – user2357112
[如何查找列表中所有元素的出现?](http://stackoverflow.com/questions/6294179/how-to-find-all-occurrences-of-an-element-in-a -list) – TemporalWolf