def key(b, p):
    if p[0] != b[0]:
        return float(p[1] - b[1]) / float(p[0] - b[0]), p[0] < b[0]
if p[1] != b[1]:
    return None, p[1] < b[1]
return None

def between1(b, p, q):
    return b <= p <= q or q <= p <= b

def between2_assume_collinear(b, p, q):
    return between1(b[0], p[0], q[0]) and between1(b[1], p[1], q[1])

def unblocked(b, l1, l2):
    inner = {}
for p in l2:
    k = key(b, p)
if k is None:
    return
q = inner.get(k)
if q is None or between2_assume_collinear(b, p, q):
    inner[k] = p
for q in l1:
    p = inner.get(key(b, q))
if p is None or not between2_assume_collinear(b, p, q):
    yield q
Самый быстрый способ проверить, находится ли какая-либо точка из списка между двумя фиксированными точками A и B.