def change_width_of_rdd_row(new_widths, old_widths, which_element, row):
    """
    Zero pads the fixed width of each geolevel in a DAS_GEOID to ensure that the number of additional digits required to
    represent each of the geolevels are given by new_widths rather than old_widths.
    :param new_widths: the geolevel widths in the initial DAS_GEOID
    :param old_widths: the geolevel widths in the DAS_GEOID in the output row
    :param which_element: the index of the input row that has the DAS_GEOID
    :param row: an RDD row formatted as (x, DAS_GEOID) if which_element == 1 and (DAS_GEOID, x) if which_element == 0

    :return new_row: an RDD row formatted as (x, new_DAS_GEOID) if which_element == 1 and (new_DAS_GEOID, x) if
    which_element == 0
    """
    # Zero pads the fixed width of each geolevel in a geocode to ensure that the number of additional digits required to
    # represent each of the geolevels are given by new_widths rather than old_widths.
    # new_widths and old_widths are tuples of integers.
    # row is a tuple formatted as: (x_i, DAS_id_i) if which_element == 1 and (DAS_id_i, x_i) if which_element == 0.
    DAS_id = row[which_element]

    message = f'change_width_of_rdd_row can only increase number of additional digits required for a geolevel.'
    for old_width, new_width in zip(old_widths, new_widths):
        assert old_width <= new_width, message

    cur_index = 0
    for k in range(len(old_widths)):
        if len(DAS_id) < (cur_index + old_widths[k]):
            break
        if old_widths[k] < new_widths[k]:
            id_left = DAS_id[:cur_index]
            id_right = DAS_id[cur_index:]
            id_center = '0' * (new_widths[k] - old_widths[k])
            DAS_id = id_left + id_center + id_right
            cur_index += new_widths[k]
        else:
            cur_index += old_widths[k]

    if which_element == 0:
        return DAS_id, row[1]
    return row[0], DAS_id