given interval defined start , end point (both floats), determine intersection range second interval. example: int1 = [2. , 5.] int2 = [2.2, 7.] >>> desired_function(int1, int2) 2.8 it should handle intersection possibilities (no intersection, partial intersection, complete intersection, negative ranges etc.). attempt looks this: def intersection(int1, int2): #case 1: partial intersection on left or right border if (int2[0]<=int1[0] , int2[1]<=int1[1]) or (int2[0]>=int1[0] , int2[1]>=int1[1]): return min(int1[1],int2[1]) - max(int1[0],int2[0]) #case 2: complete overlap of 1 interval other elif (int2[0]>=int1[0] , int2[1]<=int1[1]) or (int2[0]<=int1[0] , int2[1]>=int1[1]): return min (int2[1]-int2[0] , int1[1]-int1[0]) #case 3: no overlap @ else: return 0 question: have missed , there build-in solution or package similar since want keep code simple , fast possible? you making thing...