[英]searching index of tuple from list of tuples
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. 我想在tupleList中找到
('a','b')
的索引。
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]
[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? 请参阅如何查找列表中所有出现的元素?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.