import bisect


def find_closest(timestamps, t):
    """
    Function that finds the nearest timestamp to t in timestamps
    :param timestamps: List of timestamps
    :param t: Timestamp to find nearest to
    :return: Index in the list of timestamps
    """
    # https://stackoverflow.com/questions/29525050/nearest-timestamp-price-ready-data-structure-in-python
    idx = bisect.bisect_left(timestamps, t)  # Find insertion point
    # Check which timestamp with idx or idx - 1 is closer
    if idx > 0 and abs(timestamps[idx] - t) > abs(timestamps[idx - 1] - t):
         idx -= 1
    return idx