def write_datapoints(datapoints, writer):
    """
    write datapoints to a file, remember the beginning and ending lines for the yes/no questions
    :param datapoints: List[Dict] a batch of data points
    :param writer: file handler of a file to write to
    :return: examples List[Tuple[int, int]] the beginning and ending lines for the yes/no questions
    """
    examples = []  # holds beginning and ending lines of each example in the respective file
    start = 0
    ex_id = None
    for dp_idx, datapoint in enumerate(datapoints):
        if ex_id is not None and datapoint['example_id'] != ex_id:
            end = dp_idx
            examples.append((start, end))
            start = end
        ex_id = datapoint['example_id']
        writer.write(datapoint)
    return examples, start