<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def rename_keys(d, keymap=None, list_of_dicts=False, deepcopy=True):
 """ 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 -------- {'a': {'new_name': 1}} """

    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)