8.2.8.7. kk_dict

kk_dict(*kk, **adict)[source]

Merges and defines dictionaries with values identical to keys.

Parameters:
  • kk (object | dict, optional) – A sequence of keys and/or dictionaries.
  • adict (dict, optional) – A dictionary.
Returns:

Merged dictionary.

Return type:

dict

Example:

>>> sorted(kk_dict('a', 'b', 'c').items())
[('a', 'a'), ('b', 'b'), ('c', 'c')]

>>> sorted(kk_dict('a', 'b', **{'a-c': 'c'}).items())
[('a', 'a'), ('a-c', 'c'), ('b', 'b')]

>>> sorted(kk_dict('a', {'b': 'c'}, 'c').items())
[('a', 'a'), ('b', 'c'), ('c', 'c')]

>>> sorted(kk_dict('a', 'b', **{'b': 'c'}).items())
Traceback (most recent call last):
 ...
ValueError: keyword argument repeated (b)
>>> sorted(kk_dict({'a': 0, 'b': 1}, **{'b': 2, 'a': 3}).items())
Traceback (most recent call last):
 ...
ValueError: keyword argument repeated (a, b)