From 220894e9b3dfb34832b4917896f262ae3fa3cad4 Mon Sep 17 00:00:00 2001 From: Jeremy Tan Date: Wed, 4 Oct 2023 10:28:33 +0900 Subject: [PATCH 1/2] Add typing --- sorts/topological_sort.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sorts/topological_sort.py b/sorts/topological_sort.py index 59a0c8571b53..537b4957a0cd 100644 --- a/sorts/topological_sort.py +++ b/sorts/topological_sort.py @@ -5,11 +5,11 @@ # b c # / \ # d e -edges = {"a": ["c", "b"], "b": ["d", "e"], "c": [], "d": [], "e": []} -vertices = ["a", "b", "c", "d", "e"] +edges: dict[str, list[str]] = {"a": ["c", "b"], "b": ["d", "e"], "c": [], "d": [], "e": []} +vertices: list[str] = ["a", "b", "c", "d", "e"] -def topological_sort(start, visited, sort): +def topological_sort(start: str, visited: list[str], sort: list[str]) -> list[str]: """Perform topological sort on a directed acyclic graph.""" current = start # add current to visited From ed86f1cf44ddef296df3b1bc46d67ac65951f878 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Oct 2023 01:36:39 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- sorts/topological_sort.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sorts/topological_sort.py b/sorts/topological_sort.py index 537b4957a0cd..efce8165fcac 100644 --- a/sorts/topological_sort.py +++ b/sorts/topological_sort.py @@ -5,7 +5,13 @@ # b c # / \ # d e -edges: dict[str, list[str]] = {"a": ["c", "b"], "b": ["d", "e"], "c": [], "d": [], "e": []} +edges: dict[str, list[str]] = { + "a": ["c", "b"], + "b": ["d", "e"], + "c": [], + "d": [], + "e": [], +} vertices: list[str] = ["a", "b", "c", "d", "e"]