PythiloLesson 32 of 32 · progress kept in this browser

Practice in Lab: Topological Sort →

Order tasks with depth-first topological sort

Build steps, course prerequisites and spreadsheet formulas form directed graphs without cycles. A topological order lists every task after everything it depends on.

needs = {"test": ["build"],
         "build": ["fetch"], "fetch": []}
# fetch, build, test
Your task

Write build_order(needs) where needs maps each task to the tasks it depends on. Return a list with dependencies first, visiting tasks and dependencies in the given order, or raise ValueError on a cycle.

All lessons