Skip to content

PyDrocsid.emojis

_invert_dict

_invert_dict(d: dict[str, str]) -> dict[str, list[str]]

Invert a dictionary such that every value is mapped to a list of its keys.

Source code in PyDrocsid/emojis.py
 6
 7
 8
 9
10
11
12
13
def _invert_dict(d: dict[str, str]) -> dict[str, list[str]]:
    """Invert a dictionary such that every value is mapped to a list of its keys."""

    out: dict[str, list[str]] = {}
    for k, v in d.items():
        out.setdefault(v, []).append(k)

    return out