def apply_on_element(f, args, kwargs, n):
 if isinstance(n, int):
  structure = args[n]
  is_arg = True
 elif isinstance(n, str):
  structure = kwargs[n]
  is_arg = False
 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)
 return list(map(f_reduced, structure))

def apply_on_element ( f , args , kwargs , n ) : if isinstance ( n , int ) : structure = args [ n ] is_arg = True elif isinstance ( n , str ) : structure = kwargs [ n ] is_arg = False 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 ) return list ( map ( f_reduced , structure ) )
returns a structure with the same dimension as the specified argument .