For two lists,
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)
how to let get_indices_of_a
return indices = [0, 2, 0,...]
with array(a)[indices] = b
? Is there a faster method than using a.index
, which is taking too long?
Making b
a set is a fast method of matching lists and returning indices (see compare two lists in python and return indices of matched values ), but it will lose the index of the second 1
as well as the sequence of the indices in this case.