Check if two lines (each with start-end positions) overlap in python
Check if two lines (each with start-end positions) overlap in python I have the following two sets of position each correspond to the start and end position: line T: t1-t2 (t1 = start_pos, t2 = end_pos) line S: s1-s2 (s1 = start_pos, t2 = end_pos) I want to write the algorithm in Python to check if T intersect with S. Example 1: t1-t2=55-122 and s1-s2=58-97 s1------------s2 t1-----------------t2 This should return True Example 2: t1-t2=4-66 / t1-t2=143-166 and s1-s2=80-141 s1----s2 t1--t2 t1---t2 Both instances of T should return False But why this code failed: def is_overlap(pos, dompos): """docstring for is_overlap""" t1,t2 = [int(x) for x in pos.split("-")] s1,s2 = [int(x) for x in dompos.split("-")] # Here we define the instance of overlapness if (t1 >= s1 and t2 >= s2) or (t1 >= s1 and t2 <= s2) or (t1 <= s1 and t2 >= s2) or ...