I have a number of lists that have values of either 1
or 0
and have length 1024. I would like to find the number of times that two given lists overlap over all indexes (but only if they match with values == 1), but can't seem to think of way that keeps the number of comparisons low. Currently my approach is to get all indexes of my lists where the value == 1, and get the intersection of two lists, e.g.
#for each list, do the following
for x,j in enumerate(list1):
if j == 1:
idx_list.append(x)
# compare two lists
num_overlap = set(idx_list1).intersection(idx_list2)
Is this the most efficient way to find this value?
For example input/output (only showing 6 values instead of 1024):
list1 = [1 0 1 0 0 0]
list2 = [1 0 0 0 0 0]
num_overlap = 1 (both lists have ```1``` at index 0)