I have a fairly basic question here: I want to find if two lines on a 1-D plane intersect. I know of two simple ways to solve this, but I wanted to know if Python has a more elegant way to solve this.x = [1, 10] # 1 = begin, 10 = endy = [15, 20]z = [5, 12]#Method 1: Works. Is quick. Lots of typing.def is_intersect_1(a, b):    bool_check = False    if a[0] <= b[0] <= a[1] or \    a[0] <= b[1] <= a[1] or \    b[0] <= a[0] <= b[1] or \    b[0] <= a[1] <= b[1]:        bool_check = True    return bool_checkis_intersect_1(x,y) # Falseis_intersect_1(x,z) # True#Method 2: Quicker to write. Simpler to read. Uses more memory and is slower.def is_intersect_2(a, b):    bool_check = False    if set(range(a[0], a[1]+1)).intersection(set(range(b[0], b[1])):        bool_check = True    return bool_checkis_intersect_2(x,y) # Falseis_intersect_2(x,z) # True
1-D intersection of lines given begin and end points
python;comparative review;interval;coordinate system
Using explicit booleans is a common antipattern:check = Falseif condition:    check = Truereturn checkis equivalent to much more transparent (and preferable)return conditionSegments do not intersect if a lies completely to the left, or completely to the right of b. Assuming that segments are themselves sorted:def is_intersect_3(a, b):    return not (a[1] < b[0] or a[0] > b[1])is_intersect_2 fails badly on floats