Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fc33c50

Browse files
[pre-commit.ci] pre-commit autoupdate (TheAlgorithms#12398)
updates: - [github.com/astral-sh/ruff-pre-commit: v0.4.10 → v0.5.0](astral-sh/ruff-pre-commit@v0.4.10...v0.5.0) - [github.com/pre-commit/mirrors-mypy: v1.10.0 → v1.10.1](pre-commit/mirrors-mypy@v1.10.0...v1.10.1) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent f3f32ae commit fc33c50

File tree

30 files changed

+66
-78
lines changed

30 files changed

+66
-78
lines changed

‎.pre-commit-config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
- id: auto-walrus
1717

1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.7.4
19+
rev: v0.8.0
2020
hooks:
2121
- id: ruff
2222
- id: ruff-format

‎cellular_automata/conways_game_of_life.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ def new_generation(cells: list[list[int]]) -> list[list[int]]:
5858
# 3. All other live cells die in the next generation.
5959
# Similarly, all other dead cells stay dead.
6060
alive = cells[i][j] == 1
61-
if (
62-
(alive and 2 <= neighbour_count <= 3)
63-
or not alive
64-
and neighbour_count == 3
61+
if (alive and 2 <= neighbour_count <= 3) or (
62+
not alive and neighbour_count == 3
6563
):
6664
next_generation_row.append(1)
6765
else:

‎ciphers/playfair_cipher.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from collections.abc import Generator, Iterable
2525

2626

27-
def chunker(seq: Iterable[str], size: int) -> Generator[tuple[str, ...], None, None]:
27+
def chunker(seq: Iterable[str], size: int) -> Generator[tuple[str, ...]]:
2828
it = iter(seq)
2929
while True:
3030
chunk = tuple(itertools.islice(it, size))

‎ciphers/simple_keyword_cypher.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def remove_duplicates(key: str) -> str:
1010

1111
key_no_dups = ""
1212
for ch in key:
13-
if ch == " " or ch not in key_no_dups and ch.isalpha():
13+
if ch == " " or (ch not in key_no_dups and ch.isalpha()):
1414
key_no_dups += ch
1515
return key_no_dups
1616

‎ciphers/transposition_cipher.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,8 @@ def decrypt_message(key: int, message: str) -> str:
5252
plain_text[col] += symbol
5353
col += 1
5454

55-
if (
56-
(col == num_cols)
57-
or (col == num_cols - 1)
58-
and (row >= num_rows - num_shaded_boxes)
55+
if (col == num_cols) or (
56+
(col == num_cols - 1) and (row >= num_rows - num_shaded_boxes)
5957
):
6058
col = 0
6159
row += 1

‎compression/lempel_ziv.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def add_key_to_lexicon(
3535
lexicon[curr_string + "0"] = last_match_id
3636

3737
if math.log2(index).is_integer():
38-
for curr_keyin lexicon:
39-
lexicon[curr_key] = "0"+lexicon[curr_key]
38+
for curr_key, valuein lexicon.items():
39+
lexicon[curr_key] = f"0{value}"
4040

4141
lexicon[curr_string + "1"] = bin(index)[2:]
4242

‎data_structures/arrays/sudoku_solver.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def time_solve(grid):
156156
times, results = zip(*[time_solve(grid) for grid in grids])
157157
if (n := len(grids)) > 1:
158158
print(
159-
"Solved %d of %d %s puzzles (avg %.2f secs (%d Hz), max %.2f secs)."
159+
"Solved %d of %d %s puzzles (avg %.2f secs (%d Hz), max %.2f secs)."# noqa: UP031
160160
% (sum(results), n, name, sum(times) / n, n / sum(times), max(times))
161161
)
162162

‎data_structures/binary_tree/binary_tree_traversals.py‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def make_tree() -> Node | None:
3030
return tree
3131

3232

33-
def preorder(root: Node | None) -> Generator[int, None, None]:
33+
def preorder(root: Node | None) -> Generator[int]:
3434
"""
3535
Pre-order traversal visits root node, left subtree, right subtree.
3636
>>> list(preorder(make_tree()))
@@ -43,7 +43,7 @@ def preorder(root: Node | None) -> Generator[int, None, None]:
4343
yield from preorder(root.right)
4444

4545

46-
def postorder(root: Node | None) -> Generator[int, None, None]:
46+
def postorder(root: Node | None) -> Generator[int]:
4747
"""
4848
Post-order traversal visits left subtree, right subtree, root node.
4949
>>> list(postorder(make_tree()))
@@ -56,7 +56,7 @@ def postorder(root: Node | None) -> Generator[int, None, None]:
5656
yield root.data
5757

5858

59-
def inorder(root: Node | None) -> Generator[int, None, None]:
59+
def inorder(root: Node | None) -> Generator[int]:
6060
"""
6161
In-order traversal visits left subtree, root node, right subtree.
6262
>>> list(inorder(make_tree()))
@@ -69,7 +69,7 @@ def inorder(root: Node | None) -> Generator[int, None, None]:
6969
yield from inorder(root.right)
7070

7171

72-
def reverse_inorder(root: Node | None) -> Generator[int, None, None]:
72+
def reverse_inorder(root: Node | None) -> Generator[int]:
7373
"""
7474
Reverse in-order traversal visits right subtree, root node, left subtree.
7575
>>> list(reverse_inorder(make_tree()))
@@ -93,7 +93,7 @@ def height(root: Node | None) -> int:
9393
return (max(height(root.left), height(root.right)) + 1) if root else 0
9494

9595

96-
def level_order(root: Node | None) -> Generator[int, None, None]:
96+
def level_order(root: Node | None) -> Generator[int]:
9797
"""
9898
Returns a list of nodes value from a whole binary tree in Level Order Traverse.
9999
Level Order traverse: Visit nodes of the tree level-by-level.
@@ -116,9 +116,7 @@ def level_order(root: Node | None) -> Generator[int, None, None]:
116116
process_queue.append(node.right)
117117

118118

119-
def get_nodes_from_left_to_right(
120-
root: Node | None, level: int
121-
) -> Generator[int, None, None]:
119+
def get_nodes_from_left_to_right(root: Node | None, level: int) -> Generator[int]:
122120
"""
123121
Returns a list of nodes value from a particular level:
124122
Left to right direction of the binary tree.
@@ -128,7 +126,7 @@ def get_nodes_from_left_to_right(
128126
[2, 3]
129127
"""
130128

131-
def populate_output(root: Node | None, level: int) -> Generator[int, None, None]:
129+
def populate_output(root: Node | None, level: int) -> Generator[int]:
132130
if not root:
133131
return
134132
if level == 1:
@@ -140,9 +138,7 @@ def populate_output(root: Node | None, level: int) -> Generator[int, None, None]
140138
yield from populate_output(root, level)
141139

142140

143-
def get_nodes_from_right_to_left(
144-
root: Node | None, level: int
145-
) -> Generator[int, None, None]:
141+
def get_nodes_from_right_to_left(root: Node | None, level: int) -> Generator[int]:
146142
"""
147143
Returns a list of nodes value from a particular level:
148144
Right to left direction of the binary tree.
@@ -152,7 +148,7 @@ def get_nodes_from_right_to_left(
152148
[3, 2]
153149
"""
154150

155-
def populate_output(root: Node | None, level: int) -> Generator[int, None, None]:
151+
def populate_output(root: Node | None, level: int) -> Generator[int]:
156152
if not root:
157153
return
158154
if level == 1:
@@ -164,7 +160,7 @@ def populate_output(root: Node | None, level: int) -> Generator[int, None, None]
164160
yield from populate_output(root, level)
165161

166162

167-
def zigzag(root: Node | None) -> Generator[int, None, None]:
163+
def zigzag(root: Node | None) -> Generator[int]:
168164
"""
169165
ZigZag traverse:
170166
Returns a list of nodes value from left to right and right to left, alternatively.

‎data_structures/linked_list/deque_doubly.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class _DoublyLinkedBase:
1212
"""A Private class (to be inherited)"""
1313

1414
class _Node:
15-
__slots__ = "_prev", "_data", "_next"
15+
__slots__ = "_data", "_next", "_prev"
1616

1717
def __init__(self, link_p, element, link_n):
1818
self._prev = link_p

‎data_structures/queue/double_ended_queue.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Deque:
3333
the number of nodes
3434
"""
3535

36-
__slots__ = ("_front", "_back", "_len")
36+
__slots__ = ("_back", "_front", "_len")
3737

3838
@dataclass
3939
class _Node:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /