def map_nlist(nlist, fn):
    """
    Maps `fn` to elements in nested list that has arbitrary depth.
    https://stackoverflow.com/a/26133679
    :param nlist: Input list
    :param fn: Function to be applied
    :return: Modified list
    """
    new_list = []
    for i in range(len(nlist)):
        if isinstance(nlist[i], list):
            new_list.append(map_nlist(nlist[i], fn))
        else:
            new_list.append(fn(nlist[i]))
    return new_list