def get_median(cs, min_b = 0, max_b = 1000, steps = 20):
    L, R = 0, 0
    bounds = [min_b, max_b]
    total = None

    for _ in range(steps):
        old_bounds = copy(bounds)
        # print(bounds)

        cand_median = int((bounds[1] + bounds[0]) / 2)

        if bounds[0] == cand_median:
            yield cand_median
            return

        EL = Ct.sum([ cs.estimate(i)[0] for i in range(bounds[0], cand_median) ])
        newl = yield EL # EL.dec(sec)
        
        if total is None:
            ER = Ct.sum([ cs.estimate(i)[0] for i in range(cand_median, bounds[1]) ])        
            newr = yield ER # ER.dec(sec)

            total = newl + newr
            # print("total: %s" % total)

        else:
            newr = total - newl
            if __debug__:
                ER = Ct.sum( [ cs.estimate(i)[0] for i in range(cand_median, bounds[1]) ])        
                newrx = yield ER # ER.dec(sec)
                # assert newrx == newr

        if newl + L > newr + R:
            R = R + newr
            bounds[1] = cand_median
            total = newl
        else:
            L = L + newl
            bounds[0] = cand_median
            total = newr

        if bounds == old_bounds:
            yield cand_median
            return 


#### ------------- TESTS ------------------
dataset/ETHPy150Open gdanezis/petlib/examples/tormedian.py/get_median/original