diff --git a/.flake8 b/.flake8 index 2f74f421d..b68ee8533 100644 --- a/.flake8 +++ b/.flake8 @@ -4,5 +4,7 @@ max-line-length = 88 max-complexity = 19 extend-ignore = # Formatting style for `black` - E203 # Whitespace before ':' - W503 # Line break occurred before a binary operator + # E203 is whitespace before ':' + E203, + # W503 is line break occurred before a binary operator + W503 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 324a021ee..74502b3ea 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: - id: check-executables-have-shebangs - id: check-yaml @@ -34,13 +34,13 @@ repos: - --py311-plus - repo: https://github.com/PyCQA/flake8 - rev: 5.0.4 + rev: 6.0.0 hooks: - id: flake8 # See .flake8 for args additional_dependencies: &flake8-plugins - flake8-bugbear - flake8-builtins - - flake8-broken-line + # - flake8-broken-line - flake8-comprehensions - pep8-naming diff --git a/DIRECTORY.md b/DIRECTORY.md index 83da4b76a..b3b484f73 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -375,6 +375,7 @@ * [Articulation Points](graphs/articulation_points.py) * [Basic Graphs](graphs/basic_graphs.py) * [Bellman Ford](graphs/bellman_ford.py) + * [Bi Directional Dijkstra](graphs/bi_directional_dijkstra.py) * [Bidirectional A Star](graphs/bidirectional_a_star.py) * [Bidirectional Breadth First Search](graphs/bidirectional_breadth_first_search.py) * [Boruvka](graphs/boruvka.py) @@ -563,6 +564,7 @@ * [Is Ip V4 Address Valid](maths/is_ip_v4_address_valid.py) * [Is Square Free](maths/is_square_free.py) * [Jaccard Similarity](maths/jaccard_similarity.py) + * [Juggler Sequence](maths/juggler_sequence.py) * [Kadanes](maths/kadanes.py) * [Karatsuba](maths/karatsuba.py) * [Krishnamurthy Number](maths/krishnamurthy_number.py) diff --git a/compression/huffman.py b/compression/huffman.py index b337ac3ec..65e5c2f25 100644 --- a/compression/huffman.py +++ b/compression/huffman.py @@ -32,7 +32,7 @@ def parse_file(file_path: str) -> list[Letter]: if not c: break chars[c] = chars[c] + 1 if c in chars else 1 - return sorted((Letter(c, f) for c, f in chars.items()), key=lambda l: l.freq) + return sorted((Letter(c, f) for c, f in chars.items()), key=lambda x: x.freq) def build_tree(letters: list[Letter]) -> Letter | TreeNode: @@ -47,7 +47,7 @@ def build_tree(letters: list[Letter]) -> Letter | TreeNode: total_freq = left.freq + right.freq node = TreeNode(total_freq, left, right) response.append(node) - response.sort(key=lambda l: l.freq) + response.sort(key=lambda x: x.freq) return response[0] diff --git a/data_structures/binary_tree/non_recursive_segment_tree.py b/data_structures/binary_tree/non_recursive_segment_tree.py index 075ff6c91..04164e5cb 100644 --- a/data_structures/binary_tree/non_recursive_segment_tree.py +++ b/data_structures/binary_tree/non_recursive_segment_tree.py @@ -106,7 +106,7 @@ class SegmentTree(Generic[T]): l, r = l + self.N, r + self.N res: T | None = None - while l <= r: # noqa: E741 + while l <= r: if l % 2 == 1: res = self.st[l] if res is None else self.fn(res, self.st[l]) if r % 2 == 0: diff --git a/data_structures/binary_tree/segment_tree.py b/data_structures/binary_tree/segment_tree.py index 949a3ecdd..b05803869 100644 --- a/data_structures/binary_tree/segment_tree.py +++ b/data_structures/binary_tree/segment_tree.py @@ -16,7 +16,7 @@ class SegmentTree: return idx * 2 + 1 def build(self, idx, l, r): # noqa: E741 - if l == r: # noqa: E741 + if l == r: self.st[idx] = A[l] else: mid = (l + r) // 2 @@ -33,7 +33,7 @@ class SegmentTree: """ if r < a or l > b: return True - if l == r: # noqa: E741 + if l == r: self.st[idx] = val return True mid = (l + r) // 2 @@ -51,7 +51,7 @@ class SegmentTree: """ if r < a or l > b: return -math.inf - if l >= a and r <= b: # noqa: E741 + if l >= a and r <= b: return self.st[idx] mid = (l + r) // 2 q1 = self.query_recursive(self.left(idx), l, mid, a, b) diff --git a/machine_learning/sequential_minimum_optimization.py b/machine_learning/sequential_minimum_optimization.py index 3864f6421..f5185e1d9 100644 --- a/machine_learning/sequential_minimum_optimization.py +++ b/machine_learning/sequential_minimum_optimization.py @@ -314,7 +314,7 @@ class SmoSVM: l, h = max(0.0, a2 - a1), min(self._c, self._c + a2 - a1) else: l, h = max(0.0, a2 + a1 - self._c), min(self._c, a2 + a1) - if l == h: # noqa: E741 + if l == h: return None, None # calculate eta diff --git a/project_euler/problem_107/sol1.py b/project_euler/problem_107/sol1.py index b3f5685b9..4659eac24 100644 --- a/project_euler/problem_107/sol1.py +++ b/project_euler/problem_107/sol1.py @@ -99,7 +99,6 @@ def solution(filename: str = "p107_network.txt") -> int: """ script_dir: str = os.path.abspath(os.path.dirname(__file__)) network_file: str = os.path.join(script_dir, filename) - adjacency_matrix: list[list[str]] edges: dict[EdgeT, int] = {} data: list[str] edge1: int