(f, args, kwargs, n)
return list(map(f_reduced, structure))
Returns a structure with the same dimension as the specified argument,
    where each basic element is replaced by the function f applied on it. All
    other arguments stay the same.
Returns a structure with the same dimension as the specified argument,
    where each basic element is replaced by the function f applied on it. All
    other arguments stay the same.
Returns a structure with the same dimension as the specified argument where each basic element is replaced by the function f applied on it . All other arguments stay the same .
def apply_on_element(f, args, kwargs, n):
    """
    Returns a structure with the same dimension as the specified argument,
    where each basic element is replaced by the function f applied on it. All
    other arguments stay the same.
    """
    # Get the specified argument.
    if isinstance(n, int):
        structure = args[n]
        is_arg = True
    elif isinstance(n, str):
        structure = kwargs[n]
        is_arg = False

    # Define reduced function that is only dependend of the specified argument.
    def f_reduced(x):
        if hasattr(x, "__iter__"):
            return list(map(f_reduced, x))
        else:
            if is_arg:
                args[n] = x
            else:
                kwargs[n] = x
            return f(*args, **kwargs)

    # f_reduced will call itself recursively so that in the end f is applied to
    # all basic elements.
    return list(map(f_reduced, structure))
def apply_on_element ( f , args , kwargs , n ) : # Get the specified argument. if isinstance ( n , int ) : structure = args [ n ] is_arg = True elif isinstance ( n , str ) : structure = kwargs [ n ] is_arg = False # Define reduced function that is only dependend of the specified argument. def f_reduced ( x ) : if hasattr ( x , "__iter__" ) : return list ( map ( f_reduced , x ) ) else : if is_arg : args [ n ] = x else : kwargs [ n ] = x return f ( * args , * * kwargs ) # f_reduced will call itself recursively so that in the end f is applied to # all basic elements. return list ( map ( f_reduced , structure ) )