AdvancedChallenge 28 of 34

Topological sort

Write build_order(deps) where deps maps each task to the of tasks it depends on. Return a list containing every task exactly once, such that each task comes after all of its dependencies. Raise ValueError if there is a cycle. When several orders are valid, any one is accepted.

Examples
build_order({"app": ["lib", "utils"], "lib": ["utils"], "utils": []}) → ["utils", "lib", "app"]
Exercise

Topological sort

4 checks
def build_order(deps):
    ...


print(build_order({"app": ["lib", "utils"], "lib": ["utils"], "utils": []}))
 
Python (loads on first run)Ctrl+Enter runs
Output
Press Run to try your code, then Check answer to grade it.