def reverse_edges(edges):
    """Reverses direction of dependence dict.

    Parameters
    ----------
    edges : dict
        Dict of the form {a: {b, c}, b: set(), c: set()} where b and c depend
        on a.

    Returns
    -------
    Dict of the form {a: set(), b: {a}, c: {a}} where b and c depend on a.

    Examples
    --------

    .. testcode::

       from nengo.utils.graphs import reverse_edges

       d = {0: {1, 2}, 1: {2, 3}, 2: set(), 3: set()}
       print(reverse_edges(d))

    .. testoutput::

       {0: set(), 1: {0}, 2: {0, 1}, 3: {1}}

    Notes
    -----
    dict order are not deterministic. As we iterate on the
    input dict, it make the output of this function depend on the
    dict order. So this function output order should be considered
    as undeterministic.
    """
    result = {k: set() for k in edges}
    for key in edges:
        for val in edges[key]:
            result[val].add(key)
    return result