code: def rename_keys(d, keymap=None, list_of_dicts=False, deepcopy=True):
      
      list_of_dicts = '__list__' if list_of_dicts else None
      keymap = {} if keymap is None else keymap
  
      flatd = flatten(d, list_of_dicts=list_of_dicts)
  
      flatd = {
          tuple([keymap.get(k, k) for k in path]): v for path, v in flatd.items()
      }
  
      return unflatten(flatd, list_of_dicts=list_of_dicts, deepcopy=deepcopy)
docs: rename keys in dict
  
      Parameters
      ----------
      d : dict
      keymap : dict
          dictionary of key name mappings
      list_of_dicts: bool
          treat list of dicts as additional branches
      deepcopy: bool
          deepcopy values
  
      Examples
      --------
  
      >>> from pprint import pprint
      >>> d = {'a':{'old_name':1}}
      >>> pprint(rename_keys(d,{'old_name':'new_name'}))
      {'a': {'new_name': 1}}