code: 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 dependent on 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))
  
imports: from functools import wraps
label_desc: Use image node_id 1 for calling a global function with example usage: apply_on_element(f, args, kwargs, n) and returns: list, list, f