Reputation: 4807
I have a list of tuples as follows:
tupleList = [('a','b'), ('c','d'), ('a','b'), ('a','b'), ('e','f')]
I want to find index of ('a','b')
in tupleList.
I am trying the following:
idx = np.where(tupleList == ('a','b'))
but it gives an empty array.
Desired output would be
idx = [0, 2, 3]
Upvotes: 1
Views: 44
Reputation: 7952
[i for i, t in enumerate(tupleList) if t == ('a', 'b')]
yields
[0, 2, 3]
see How to find all occurrences of an element in a list?
Upvotes: 3