import bisect


def clip_around_detections_instant(detections, time):
    """Return the narrowest sublist of detections (a list of Detections)
    containing time.  If there is a detection at exactly time, try to
    expand in either direction.

    """
    times = [d.timestamp for d in detections]
    lo = max(bisect.bisect_left(times, time) - 1, 0)
    hi = min(bisect.bisect(times, time) + 1, len(times))
    return detections[lo:hi]