mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
[Upgrade Ruff] Fix all errors raised from ruff (#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>
This commit is contained in:
parent
5aefc00f0f
commit
93fb169627
|
@ -16,7 +16,7 @@ repos:
|
|||
- id: auto-walrus
|
||||
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.0.278
|
||||
rev: v0.0.280
|
||||
hooks:
|
||||
- id: ruff
|
||||
|
||||
|
|
|
@ -98,7 +98,7 @@ def __judge_point(pt: bool, neighbours: list[list[bool]]) -> bool:
|
|||
if pt:
|
||||
if alive < 2:
|
||||
state = False
|
||||
elif alive == 2 or alive == 3:
|
||||
elif alive in {2, 3}:
|
||||
state = True
|
||||
elif alive > 3:
|
||||
state = False
|
||||
|
|
|
@ -152,7 +152,7 @@ class RedBlackTree:
|
|||
self.grandparent.color = 1
|
||||
self.grandparent._insert_repair()
|
||||
|
||||
def remove(self, label: int) -> RedBlackTree:
|
||||
def remove(self, label: int) -> RedBlackTree: # noqa: PLR0912
|
||||
"""Remove label from this tree."""
|
||||
if self.label == label:
|
||||
if self.left and self.right:
|
||||
|
|
|
@ -156,7 +156,7 @@ class RadixNode:
|
|||
del self.nodes[word[0]]
|
||||
# We merge the current node with its only child
|
||||
if len(self.nodes) == 1 and not self.is_leaf:
|
||||
merging_node = list(self.nodes.values())[0]
|
||||
merging_node = next(iter(self.nodes.values()))
|
||||
self.is_leaf = merging_node.is_leaf
|
||||
self.prefix += merging_node.prefix
|
||||
self.nodes = merging_node.nodes
|
||||
|
@ -165,7 +165,7 @@ class RadixNode:
|
|||
incoming_node.is_leaf = False
|
||||
# If there is 1 edge, we merge it with its child
|
||||
else:
|
||||
merging_node = list(incoming_node.nodes.values())[0]
|
||||
merging_node = next(iter(incoming_node.nodes.values()))
|
||||
incoming_node.is_leaf = merging_node.is_leaf
|
||||
incoming_node.prefix += merging_node.prefix
|
||||
incoming_node.nodes = merging_node.nodes
|
||||
|
|
|
@ -266,7 +266,7 @@ def convex_hull_bf(points: list[Point]) -> list[Point]:
|
|||
points_left_of_ij = points_right_of_ij = False
|
||||
ij_part_of_convex_hull = True
|
||||
for k in range(n):
|
||||
if k != i and k != j:
|
||||
if k not in {i, j}:
|
||||
det_k = _det(points[i], points[j], points[k])
|
||||
|
||||
if det_k > 0:
|
||||
|
|
|
@ -39,7 +39,7 @@ class DirectedGraph:
|
|||
stack = []
|
||||
visited = []
|
||||
if s == -2:
|
||||
s = list(self.graph)[0]
|
||||
s = next(iter(self.graph))
|
||||
stack.append(s)
|
||||
visited.append(s)
|
||||
ss = s
|
||||
|
@ -87,7 +87,7 @@ class DirectedGraph:
|
|||
d = deque()
|
||||
visited = []
|
||||
if s == -2:
|
||||
s = list(self.graph)[0]
|
||||
s = next(iter(self.graph))
|
||||
d.append(s)
|
||||
visited.append(s)
|
||||
while d:
|
||||
|
@ -114,7 +114,7 @@ class DirectedGraph:
|
|||
stack = []
|
||||
visited = []
|
||||
if s == -2:
|
||||
s = list(self.graph)[0]
|
||||
s = next(iter(self.graph))
|
||||
stack.append(s)
|
||||
visited.append(s)
|
||||
ss = s
|
||||
|
@ -146,7 +146,7 @@ class DirectedGraph:
|
|||
def cycle_nodes(self):
|
||||
stack = []
|
||||
visited = []
|
||||
s = list(self.graph)[0]
|
||||
s = next(iter(self.graph))
|
||||
stack.append(s)
|
||||
visited.append(s)
|
||||
parent = -2
|
||||
|
@ -199,7 +199,7 @@ class DirectedGraph:
|
|||
def has_cycle(self):
|
||||
stack = []
|
||||
visited = []
|
||||
s = list(self.graph)[0]
|
||||
s = next(iter(self.graph))
|
||||
stack.append(s)
|
||||
visited.append(s)
|
||||
parent = -2
|
||||
|
@ -305,7 +305,7 @@ class Graph:
|
|||
stack = []
|
||||
visited = []
|
||||
if s == -2:
|
||||
s = list(self.graph)[0]
|
||||
s = next(iter(self.graph))
|
||||
stack.append(s)
|
||||
visited.append(s)
|
||||
ss = s
|
||||
|
@ -353,7 +353,7 @@ class Graph:
|
|||
d = deque()
|
||||
visited = []
|
||||
if s == -2:
|
||||
s = list(self.graph)[0]
|
||||
s = next(iter(self.graph))
|
||||
d.append(s)
|
||||
visited.append(s)
|
||||
while d:
|
||||
|
@ -371,7 +371,7 @@ class Graph:
|
|||
def cycle_nodes(self):
|
||||
stack = []
|
||||
visited = []
|
||||
s = list(self.graph)[0]
|
||||
s = next(iter(self.graph))
|
||||
stack.append(s)
|
||||
visited.append(s)
|
||||
parent = -2
|
||||
|
@ -424,7 +424,7 @@ class Graph:
|
|||
def has_cycle(self):
|
||||
stack = []
|
||||
visited = []
|
||||
s = list(self.graph)[0]
|
||||
s = next(iter(self.graph))
|
||||
stack.append(s)
|
||||
visited.append(s)
|
||||
parent = -2
|
||||
|
|
|
@ -113,7 +113,7 @@ class PushRelabelExecutor(MaximumFlowAlgorithmExecutor):
|
|||
vertices_list = [
|
||||
i
|
||||
for i in range(self.verticies_count)
|
||||
if i != self.source_index and i != self.sink_index
|
||||
if i not in {self.source_index, self.sink_index}
|
||||
]
|
||||
|
||||
# move through list
|
||||
|
|
|
@ -55,7 +55,7 @@ def factorial_recursive(n: int) -> int:
|
|||
raise ValueError("factorial() only accepts integral values")
|
||||
if n < 0:
|
||||
raise ValueError("factorial() not defined for negative values")
|
||||
return 1 if n == 0 or n == 1 else n * factorial(n - 1)
|
||||
return 1 if n in {0, 1} else n * factorial(n - 1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -154,7 +154,7 @@ def prime_factorization(number):
|
|||
|
||||
quotient = number
|
||||
|
||||
if number == 0 or number == 1:
|
||||
if number in {0, 1}:
|
||||
ans.append(number)
|
||||
|
||||
# if 'number' not prime then builds the prime factorization of 'number'
|
||||
|
|
|
@ -253,7 +253,7 @@ def find_unit_clauses(
|
|||
unit_symbols = []
|
||||
for clause in clauses:
|
||||
if len(clause) == 1:
|
||||
unit_symbols.append(list(clause.literals.keys())[0])
|
||||
unit_symbols.append(next(iter(clause.literals.keys())))
|
||||
else:
|
||||
f_count, n_count = 0, 0
|
||||
for literal, value in clause.literals.items():
|
||||
|
|
|
@ -28,12 +28,16 @@ def solution() -> int:
|
|||
31875000
|
||||
"""
|
||||
|
||||
return [
|
||||
return next(
|
||||
iter(
|
||||
[
|
||||
a * b * (1000 - a - b)
|
||||
for a in range(1, 999)
|
||||
for b in range(a, 999)
|
||||
if (a * a + b * b == (1000 - a - b) ** 2)
|
||||
][0]
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -107,7 +107,7 @@ def ripple_adder(
|
|||
res = qiskit.execute(circuit, backend, shots=1).result()
|
||||
|
||||
# The result is in binary. Convert it back to int
|
||||
return int(list(res.get_counts())[0], 2)
|
||||
return int(next(iter(res.get_counts())), 2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
@ -61,7 +61,7 @@ def assemble_transformation(ops: list[list[str]], i: int, j: int) -> list[str]:
|
|||
if i == 0 and j == 0:
|
||||
return []
|
||||
else:
|
||||
if ops[i][j][0] == "C" or ops[i][j][0] == "R":
|
||||
if ops[i][j][0] in {"C", "R"}:
|
||||
seq = assemble_transformation(ops, i - 1, j - 1)
|
||||
seq.append(ops[i][j])
|
||||
return seq
|
||||
|
|
|
@ -90,9 +90,7 @@ def convert(number: int) -> str:
|
|||
else:
|
||||
addition = ""
|
||||
if counter in placevalue:
|
||||
if current == 0 and ((temp_num % 100) // 10) == 0:
|
||||
addition = ""
|
||||
else:
|
||||
if current != 0 and ((temp_num % 100) // 10) != 0:
|
||||
addition = placevalue[counter]
|
||||
if ((temp_num % 100) // 10) == 1:
|
||||
words = teens[current] + addition + words
|
||||
|
|
Loading…
Reference in New Issue
Block a user