import types


def function_with_default(f, default):
  """Creates a new function with a default last parameter."""
  return types.FunctionType(f.__code__, f.__globals__, f.__name__,
                            (default,), f.__closure__)