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 93fb169

Browse files
CaedenPHpre-commit-ci[bot]cclauss
authored
[Upgrade Ruff] Fix all errors raised from ruff (TheAlgorithms#8879)
* chore: Fix tests * chore: Fix failing ruff * chore: Fix ruff errors * chore: Fix ruff errors * chore: Fix ruff errors * chore: Fix ruff errors * chore: Fix ruff errors * chore: Fix ruff errors * chore: Fix ruff errors * chore: Fix ruff errors * chore: Fix ruff errors * chore: Fix ruff errors * chore: Fix ruff errors * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * chore: Fix ruff errors * chore: Fix ruff errors * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update cellular_automata/game_of_life.py Co-authored-by: Christian Clauss <cclauss@me.com> * chore: Update ruff version in pre-commit * chore: Fix ruff errors * Update edmonds_karp_multiple_source_and_sink.py * Update factorial.py * Update primelib.py * Update min_cost_string_conversion.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent 5aefc00 commit 93fb169

File tree

14 files changed

+32
-30
lines changed

14 files changed

+32
-30
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.0.278
19+
rev: v0.0.280
2020
hooks:
2121
- id: ruff
2222

‎cellular_automata/game_of_life.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __judge_point(pt: bool, neighbours: list[list[bool]]) -> bool:
9898
if pt:
9999
if alive < 2:
100100
state = False
101-
elif alive ==2oralive==3:
101+
elif alive in {2, 3}:
102102
state = True
103103
elif alive > 3:
104104
state = False

‎data_structures/binary_tree/red_black_tree.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def _insert_repair(self) -> None:
152152
self.grandparent.color = 1
153153
self.grandparent._insert_repair()
154154

155-
def remove(self, label: int) -> RedBlackTree:
155+
def remove(self, label: int) -> RedBlackTree:# noqa: PLR0912
156156
"""Remove label from this tree."""
157157
if self.label == label:
158158
if self.left and self.right:

‎data_structures/trie/radix_tree.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def delete(self, word: str) -> bool:
156156
del self.nodes[word[0]]
157157
# We merge the current node with its only child
158158
if len(self.nodes) == 1 and not self.is_leaf:
159-
merging_node = list(self.nodes.values())[0]
159+
merging_node = next(iter(self.nodes.values()))
160160
self.is_leaf = merging_node.is_leaf
161161
self.prefix += merging_node.prefix
162162
self.nodes = merging_node.nodes
@@ -165,7 +165,7 @@ def delete(self, word: str) -> bool:
165165
incoming_node.is_leaf = False
166166
# If there is 1 edge, we merge it with its child
167167
else:
168-
merging_node = list(incoming_node.nodes.values())[0]
168+
merging_node = next(iter(incoming_node.nodes.values()))
169169
incoming_node.is_leaf = merging_node.is_leaf
170170
incoming_node.prefix += merging_node.prefix
171171
incoming_node.nodes = merging_node.nodes

‎divide_and_conquer/convex_hull.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def convex_hull_bf(points: list[Point]) -> list[Point]:
266266
points_left_of_ij = points_right_of_ij = False
267267
ij_part_of_convex_hull = True
268268
for k in range(n):
269-
if k !=iandk!=j:
269+
if k notin {i, j}:
270270
det_k = _det(points[i], points[j], points[k])
271271

272272
if det_k > 0:

‎graphs/directed_and_undirected_(weighted)_graph.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def dfs(self, s=-2, d=-1):
3939
stack = []
4040
visited = []
4141
if s == -2:
42-
s = list(self.graph)[0]
42+
s = next(iter(self.graph))
4343
stack.append(s)
4444
visited.append(s)
4545
ss = s
@@ -87,7 +87,7 @@ def bfs(self, s=-2):
8787
d = deque()
8888
visited = []
8989
if s == -2:
90-
s = list(self.graph)[0]
90+
s = next(iter(self.graph))
9191
d.append(s)
9292
visited.append(s)
9393
while d:
@@ -114,7 +114,7 @@ def topological_sort(self, s=-2):
114114
stack = []
115115
visited = []
116116
if s == -2:
117-
s = list(self.graph)[0]
117+
s = next(iter(self.graph))
118118
stack.append(s)
119119
visited.append(s)
120120
ss = s
@@ -146,7 +146,7 @@ def topological_sort(self, s=-2):
146146
def cycle_nodes(self):
147147
stack = []
148148
visited = []
149-
s = list(self.graph)[0]
149+
s = next(iter(self.graph))
150150
stack.append(s)
151151
visited.append(s)
152152
parent = -2
@@ -199,7 +199,7 @@ def cycle_nodes(self):
199199
def has_cycle(self):
200200
stack = []
201201
visited = []
202-
s = list(self.graph)[0]
202+
s = next(iter(self.graph))
203203
stack.append(s)
204204
visited.append(s)
205205
parent = -2
@@ -305,7 +305,7 @@ def dfs(self, s=-2, d=-1):
305305
stack = []
306306
visited = []
307307
if s == -2:
308-
s = list(self.graph)[0]
308+
s = next(iter(self.graph))
309309
stack.append(s)
310310
visited.append(s)
311311
ss = s
@@ -353,7 +353,7 @@ def bfs(self, s=-2):
353353
d = deque()
354354
visited = []
355355
if s == -2:
356-
s = list(self.graph)[0]
356+
s = next(iter(self.graph))
357357
d.append(s)
358358
visited.append(s)
359359
while d:
@@ -371,7 +371,7 @@ def degree(self, u):
371371
def cycle_nodes(self):
372372
stack = []
373373
visited = []
374-
s = list(self.graph)[0]
374+
s = next(iter(self.graph))
375375
stack.append(s)
376376
visited.append(s)
377377
parent = -2
@@ -424,7 +424,7 @@ def cycle_nodes(self):
424424
def has_cycle(self):
425425
stack = []
426426
visited = []
427-
s = list(self.graph)[0]
427+
s = next(iter(self.graph))
428428
stack.append(s)
429429
visited.append(s)
430430
parent = -2

‎graphs/edmonds_karp_multiple_source_and_sink.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _algorithm(self):
113113
vertices_list = [
114114
i
115115
for i in range(self.verticies_count)
116-
if i !=self.source_indexandi!=self.sink_index
116+
if i notin {self.source_index, self.sink_index}
117117
]
118118

119119
# move through list

‎maths/factorial.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def factorial_recursive(n: int) -> int:
5555
raise ValueError("factorial() only accepts integral values")
5656
if n < 0:
5757
raise ValueError("factorial() not defined for negative values")
58-
return 1 if n ==0orn==1 else n * factorial(n - 1)
58+
return 1 if n in {0, 1} else n * factorial(n - 1)
5959

6060

6161
if __name__ == "__main__":

‎maths/primelib.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def prime_factorization(number):
154154

155155
quotient = number
156156

157-
if number ==0ornumber==1:
157+
if number in {0, 1}:
158158
ans.append(number)
159159

160160
# if 'number' not prime then builds the prime factorization of 'number'

‎other/davisb_putnamb_logemannb_loveland.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def find_unit_clauses(
253253
unit_symbols = []
254254
for clause in clauses:
255255
if len(clause) == 1:
256-
unit_symbols.append(list(clause.literals.keys())[0])
256+
unit_symbols.append(next(iter(clause.literals.keys())))
257257
else:
258258
f_count, n_count = 0, 0
259259
for literal, value in clause.literals.items():

0 commit comments

Comments
(0)

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