Repository navigation
Is there a faster alternative to Python's built-in set.intersection() for large datasets? #15739
Replies: 1 comment
|
For general Python objects, 1. Make sure both sides are sets
b = set(big_list) # once
for a in many_sets:
common = a & b2. Many sets: start with the smallest common = set.intersection(*sorted(sets, key=len))The intermediate result can only shrink, so starting with the smallest keeps every step cheap. 3. Don't build the result if you don't need it If you only need to know whether they overlap, 4. Change the representation for big numeric data
Benchmark with |
Uh oh!
There was an error while loading. Please reload this page.
??
All reactions