Determing whether two ranges overlap

Paul McGuire ptmcg at austin.rr.com
Thu Feb 16 10:48:18 EST 2006


Robin Haswell wrote:
> Hey guys
>
> I was wondering if you could give me a hand with something. If I have two
> tuples that define a range, eg: (10, 20), (15, 30), I need to determine
> whether the ranges overlap each other.

def overlap(a,b):
    return a[0] <= b[0] <= a[1] or b[0] <= a[0] <= b[1]

-- Paul




More information about the Python-list mailing list