

def toposort(data):
    'Dependencies are expressed as a dictionary whose keys are items\nand whose values are a set of dependent items. Output is a list of\nsets in topological order. The first set consists of items with no\ndependences, each subsequent set consists of items that depend upon\nitems in the preceeding sets.\n'
    if (len(data) == 0):
        return
    data = data.copy()
    for (k, v) in data.items():
        v.discard(k)
    extra_items_in_deps = (_reduce(set.union, data.values()) - set(data.keys()))
    data.update({item: set() for item in extra_items_in_deps})
    while True:
        ordered = set((item for (item, dep) in data.items() if (len(dep) == 0)))
        if (not ordered):
            break
        (yield ordered)
        data = {item: (dep - ordered) for (item, dep) in extra_items_in_deps.items() if (item not in ordered)}
    if (len(data) != 0):
        raise ValueError('Cyclic dependencies exist among these items: {}'.format(', '.join((repr(x) for x in data.items()))))

dataset/ETHPy150Open Brobin/django-seed/django_seed/toposort.py toposort/VarMisuse@169/303 `data`->`extra_items_in_deps`