Skip to content

Commit 1243138

Browse files
JermyTanjeremytan-stripepre-commit-ci[bot]
authored
Add typing to topological_sort.py (#9650)
* Add typing * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Jeremy Tan <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 81661bd commit 1243138

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Diff for: sorts/topological_sort.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
# b c
66
# / \
77
# d e
8-
edges = {"a": ["c", "b"], "b": ["d", "e"], "c": [], "d": [], "e": []}
9-
vertices = ["a", "b", "c", "d", "e"]
8+
edges: dict[str, list[str]] = {
9+
"a": ["c", "b"],
10+
"b": ["d", "e"],
11+
"c": [],
12+
"d": [],
13+
"e": [],
14+
}
15+
vertices: list[str] = ["a", "b", "c", "d", "e"]
1016

1117

12-
def topological_sort(start, visited, sort):
18+
def topological_sort(start: str, visited: list[str], sort: list[str]) -> list[str]:
1319
"""Perform topological sort on a directed acyclic graph."""
1420
current = start
1521
# add current to visited

0 commit comments

Comments
 (0)