def map_dict(d, fn):
  """Recursively does operations to all values in a nested dictionary and
  returns a new dictionary of the result.

  Arguments: \n
  d = dictionary to do operations on \n
  fn = function to apply\n"""
  o = {}
  for key, value in d.items():
    if isinstance(value, dict):
      o[key] = map_dict(value, fn)
    else:
      o[key] = fn(value)
  return o