对于两个列表,
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
返回indices = [0, 2, 0,...]
,并使用array(a)[indices] = b
? 是否有比使用a.index
更快的方法?将b
变成集合是匹配列表和返回索引的快速方法(参见compare two lists in python and return indices of matched values),但在这种情况下会失去第二个1
的索引以及索引序列。