If you are looking for a Python library that handles arithmetic intervals, consider python-interval . Disclaimer: I support this library.
This library has support for checking matches and automatically merging intervals. For example:
>>> import intervals as I >>> I.closed(1,2) | I.closed(2,3) [1,3] >>> I.closed(1,2).overlaps(I.closed(3,4)) False
If you want to specifically calculate the overlap:
>>> I.closed(1,3) & I.closed(2, 4) [2,3]
It supports open / closed intervals, finite or infinite. To remove intervals for a given one, simply use the difference operator:
>>> I.closed(1, 4) - I.closed(2, 3) [1,2) | (3,4]
I can help you if you can be a little more specific.
Guybrush
source share