【发布时间】:2012-05-10 06:26:48
【问题描述】:
对于两个列表,
a = [1, 2, 9, 3, 8, ...] (no duplicate values in a, but a is very big)
b = [1, 9, 1,...] (set(b) is a subset of set(a), 1<<len(b)<<len(a))
indices = get_indices_of_a(a, b)
如何让get_indices_of_a 用array(a)[indices] = b 返回indices = [0, 2, 0,...]?有没有比a.index更快的方法,耗时太长?
将b 设为一个集合是匹配列表和返回索引的快速方法(参见compare two lists in python and return indices of matched values),但在这种情况下它将丢失第二个1 的索引以及索引的序列。
【问题讨论】:
标签: python list set match indices