def reverse_dict(d):
    """
    >>> a, b, c = 'abc'
    >>> d = {a: [b, c], b: [c]}
    >>> dd = reverse_dict(d)
    >>> from pprint import pprint
    >>> pprint({k: sorted(v) for k, v in dd.items()})
    {'a': [], 'b': ['a'], 'c': ['a', 'b']}
    """
    result = defaultdict(set)
    _add = set.add
    for k, vals in d.items():
        result[k]
        for val in vals:
            _add(result[val], k)
    result.default_factory = None
    return result

    >>> a, b, c = 'abc'
    >>> d = {a: [b, c], b: [c]}
    >>> dd = reverse_dict(d)
    >>> from pprint import pprint
    >>> pprint({k: sorted(v) for k, v in dd.items()})
    {'a': [], 'b': ['a'], 'c': ['a', 'b']}
    
src/flash/core/serve/dag/task.py