7.2.8.9. map_list

map_list(key_map, *inputs, copy=False, base=None)[source]

Returns a new dict.

Parameters:
  • key_map (list[str | dict | list]) – A list that maps the dict keys ({old key: new key}
  • inputs (iterable | dict | int | float | list | tuple) – A sequence of data.
  • 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 values.

Return type:

dict

Example:

>>> key_map = [
...     'a',
...     {'a': 'c'},
...     [
...         'a',
...         {'a': 'd'}
...     ]
... ]
>>> inputs = (
...     2,
...     {'a': 3, 'b': 2},
...     [
...         1,
...         {'a': 4}
...     ]
... )
>>> d = map_list(key_map, *inputs)
>>> sorted(d.items())
[('a', 1), ('b', 2), ('c', 3), ('d', 4)]