def topological_order(graph):
    V = range(len(graph))
    indeg = [0 for _ in V]
    for node in V:    # determiner degree entrant
        for neighbor in graph[node]:
            indeg[neighbor] += 1
    Q = [node for node in V if indeg[node] == 0]
    order = []
    while Q:
        node = Q.pop()                # sommet sans arc entrant
        order.append(node)
        for neighbor in graph[node]:
            indeg[neighbor] -= 1
            if indeg[neighbor] == 0:
                Q.append(neighbor)
    return order
# snip}
Topological sorting by maintaining indegree
dataset/ETHPy150Open jilljenn/tryalgo/tryalgo/topological_order.py/topological_order