def nearest(items, pivot):
    """
    General function for finding the entry in items that is nearest to pivot.

    :param items: Array of numbers or datetime objects
    :param pivot: Single number of datetime object
    :return:
    """
    return min(items, key=lambda x: abs(x - pivot))