Schedule dependencies with indegrees
A directed edge from a prerequisite to a dependent task means the prerequisite must run first. Count incoming edges and begin with nodes whose counts are zero. Removing one ready node releases its outgoing edges. If unfinished nodes remain but none is ready, the graph contains a cycle and no valid schedule exists.
from collections import deque
ready = deque(["parse"])
print(ready.popleft())Think before coding
An indegree of zero proves that every prerequisite has already been removed. A cycle never releases its final incoming edges. The algorithm touches every node and edge once. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
Your task
Write task_order(graph). The dict maps every node to its outgoing neighbours, and every neighbour is also a key. Return any topological ordering, or None for a cycle. Include isolated nodes.
The explanation opens here once every check passes.