{"library":"toposort","code":"from toposort import toposort, toposort_flatten\n\ndata = {\n    2: {11},\n    9: {11, 8, 10},\n    10: {11, 3},\n    11: {7, 5},\n    8: {7, 3},\n    # Nodes 3, 5, 7 have no dependencies, so they can be omitted\n    # or explicitly listed with empty sets if they have no outgoing edges\n    3: set(),\n    5: set(),\n    7: set()\n}\n\n# Get items in stages (sets of items that can be processed in parallel)\n# Example output: [{3, 5, 7}, {8, 11}, {2, 10}, {9}]\nfor step in toposort(data):\n    print(f\"Process in parallel: {step}\")\n\n# Get a flattened list of items in a valid order\n# Example output: [3, 5, 7, 8, 11, 2, 10, 9] (order within sets may vary)\nflattened_order = list(toposort_flatten(data))\nprint(f\"Flattened order: {flattened_order}\")\n\n# Example of circular dependency handling\ncyclic_data = {1: {2}, 2: {1}}\ntry:\n    list(toposort(cyclic_data))\nexcept toposort.CircularDependencyError as e:\n    print(f\"Caught expected error: {e}\")","lang":"python","description":"This quickstart demonstrates how to use `toposort` with a sample dependency graph. The `data` dictionary maps each dependent node to a set of its direct dependencies. `toposort` yields sets of nodes that can be processed concurrently, while `toposort_flatten` provides a single linear sequence. It also shows how to catch `CircularDependencyError` for graphs containing cycles.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}