def transform_data(function, input_data):

    ''' a function to apply a function to each value in a nested dictionary

    :param function: callable function with a single input of any datatype
    :param input_data: dictionary or list with nested data to transform
    :return: dictionary or list with data transformed by function
    '''

# construct copy
    try:
        from copy import deepcopy
        output_data = deepcopy(input_data)
    except:
        raise ValueError('transform_data() input_data argument cannot contain module datatypes.')

# walk over data and apply function
    for dot_path, value in walk_data(input_data):
        current_endpoint = output_data
        segment_list = segment_path(dot_path)
        segment = None
        if segment_list:
            for i in range(len(segment_list)):
                try:
                    segment = int(segment_list[i])
                except:
                    segment = segment_list[i]
                if i + 1 == len(segment_list):
                    pass
                else:
                    current_endpoint = current_endpoint[segment]
            current_endpoint[segment] = function(value)

    return output_data
a function to apply a function to each value in a nested dictionary

    :param function: callable function with a single input of any datatype
    :param input_data: dictionary or list with nested data to transform
    :return: dictionary or list with data transformed by function