epy.zip_dict

Contents

epy.zip_dict#

etils.epy.zip_dict(*dicts: Unpack[dict[_KeyT, _ValuesT]]) Iterator[_KeyT, tuple[Unpack[_ValuesT]]][source]#

Iterate over items of dictionaries grouped by their keys.

Example:

d0 = {'a': 1, 'b': 2}
d1 = {'a': 10, 'b': 20}
d2 = {'a': 100, 'b': 200}

list(epy.zip_dict(d0, d1, d2)) == [
    ('a', (1, 10, 100)),
    ('b', (2, 20, 200)),
]
Parameters:

*dicts – The dict to iterate over. Should all have the same keys

Yields:

The iterator of (key, zip(*values))

Raises:

KeyError – If dicts does not contain the same keys.