8.2.8.8. map_dict

map_dict(key_map, *dicts, copy=False, base=None)[source]

Returns a dict with new key values.

Parameters:
  • key_map (dict) – A dictionary that maps the dict keys ({old key: new key}
  • dicts (dict) – A sequence of dicts.
  • copy (bool, optional) – If True, it returns a deepcopy of input values.
  • base (dict, optional) – Base dict where combine multiple dicts in one.
Returns:

A unique dict with new key values.

Return type:

dict

Example:

>>> d = map_dict({'a': 'c', 'b': 'd'}, {'a': 1, 'b': 1}, {'b': 2})
>>> sorted(d.items())
[('c', 1), ('d', 2)]