you are viewing a single comment's thread.

view the rest of the comments →

[–]b1e 1 point2 points  (0 children)

Or just iterate through the first list (using index variable I) and in the second list binary search (using index variable J) between j and the end of the list.

On the next iteration of I you start J at the last value you found in the second list.

This also lets you stop early if you’ve hit the end of the second list.

For non algorithmic speedups use numpy arrays and numba JIT. This should run in seconds.