Hi,\n\nI have to read through a file that will give me a bunch of intervals.\nMy ultimate goal is to produce a final set of intervals such that not\ntwo intervals overlap by more than N, where N is a predetermined\nlength.\n\nFor example, I could read through this input:\n(1,10), (3,15), (20,30),(29,40),(51,65),(62,100),(50,66)\n\nbtw, the input is not guaranteed to be in any sorted order.\n\nsay N = 5, so the final set should be\n(1,15), (20, 30), (29, 40), (50, 100)\n\nIs there already some existing code in Python that I can easily take\nadvantage of to produce this? Right now I've written my own simple\nsolution, which is just to maintain a list of the intervals. I can use\nthe Interval module, but it doesn't really affect much. I read one\ninterval from the input file at a time, and use bisect to insert it in\norder. The problem comes with merging, which sometimes can be\ncascading.\n\nex:\nread (51,65) ==> put (51,65) in list\nread (62,100) ==> put (62,100) in list (overlap only be 4 <= N)\nread (50,66) ==> merge with (51,65) to become (50,66) ==> now can\nmerge with (62,100)\n\nOf course I can check for cascading merges by pivoting around the\nposition where the insertion would've taken place...but just\nwondering, is there some other nice way to do this? I also intuitively\ndon't sense a need for using trees, unless someone's already written\nit, the interface is easy to use, and it won't result in more insert/\ndelete/structure changes that nullifies its beauty...(also I'm not\nusing the output list for searching)\n\n\nThanks in advance.