I need to intersect a set a = {1,5,7}
with each set in a list b = [{1,2,3}, {2,3,4},...]
obtaining a new list c = [{1}, {}, ...]
.
The standard solution to this problem is a plain comprehension c = [a.intersect(b_i) for b_i in b]
, as per "intersect a list with a nested list" and the various similar posts. However, this implies a for
loop which becomes unwieldy when seeking to do 20k intersections on large sets in real time.
Is there any alternative approach to solve this problem, that might be speedier?
(as an example I was looking at the various "intersect multiple set" posts for inspiration, however that approach solves the problem of a single AND operation on n sets, not on n AND operations on n set pairs)