繁体   English   中英

从元组列表中搜索元组索引

[英]searching index of tuple from list of tuples

我有一个元组列表如下:

tupleList = [('a','b'), ('c','d'), ('a','b'), ('a','b'), ('e','f')]

我想在tupleList中找到('a','b')的索引。

我正在尝试以下方法:

idx = np.where(tupleList == ('a','b'))

但它给出了一个空数组。

期望的输出将是

idx = [0, 2, 3]
[i for i, t in enumerate(tupleList) if t == ('a', 'b')]

产量

[0, 2, 3]

请参阅如何查找列表中所有出现的元素?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM