class Multimap(dict):
    def __setitem__(self, key, value):
        if key not in self:
            dict.__setitem__(self, key, [value])
        else:
            self[key].append(value)


def get_or_none(d: dict, func):
    try:
        return func(d)
    except KeyError:
        return None


def get_or_none_by_key(d: dict, key: str):
    if key not in d:
        return None
    return d[key]
