Compare commits

..

No commits in common. "9e08c7726dee5b18585a76e54c71922ca96c0b3a" and "5aefc00f0f1c692ce772ddbc616d7cd91233236b" have entirely different histories.

16 changed files with 31 additions and 35 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: auto-walrus
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.280
rev: v0.0.278
hooks:
- id: ruff

View File

@ -25,8 +25,6 @@ We appreciate any contribution, from fixing a grammar mistake in a comment to im
Your contribution will be tested by our [automated testing on GitHub Actions](https://github.com/TheAlgorithms/Python/actions) to save time and mental energy. After you have submitted your pull request, you should see the GitHub Actions tests start to run at the bottom of your submission page. If those tests fail, then click on the ___details___ button try to read through the GitHub Actions output to understand the failure. If you do not understand, please leave a comment on your submission page and a community member will try to help.
If you are interested in resolving an [open issue](https://github.com/TheAlgorithms/Python/issues), simply make a pull request with your proposed fix. __We do not assign issues in this repo__ so please do not ask for permission to work on an issue.
Please help us keep our issue list small by adding `Fixes #{$ISSUE_NUMBER}` to the description of pull requests that resolve open issues.
For example, if your pull request fixes issue #10, then please add the following to its description:
```

View File

@ -98,7 +98,7 @@ def __judge_point(pt: bool, neighbours: list[list[bool]]) -> bool:
if pt:
if alive < 2:
state = False
elif alive in {2, 3}:
elif alive == 2 or alive == 3:
state = True
elif alive > 3:
state = False

View File

@ -152,7 +152,7 @@ class RedBlackTree:
self.grandparent.color = 1
self.grandparent._insert_repair()
def remove(self, label: int) -> RedBlackTree: # noqa: PLR0912
def remove(self, label: int) -> RedBlackTree:
"""Remove label from this tree."""
if self.label == label:
if self.left and self.right:

View File

@ -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 = next(iter(self.nodes.values()))
merging_node = list(self.nodes.values())[0]
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 = next(iter(incoming_node.nodes.values()))
merging_node = list(incoming_node.nodes.values())[0]
incoming_node.is_leaf = merging_node.is_leaf
incoming_node.prefix += merging_node.prefix
incoming_node.nodes = merging_node.nodes

View File

@ -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 not in {i, j}:
if k != i and k != j:
det_k = _det(points[i], points[j], points[k])
if det_k > 0:

View File

@ -39,7 +39,7 @@ class DirectedGraph:
stack = []
visited = []
if s == -2:
s = next(iter(self.graph))
s = list(self.graph)[0]
stack.append(s)
visited.append(s)
ss = s
@ -87,7 +87,7 @@ class DirectedGraph:
d = deque()
visited = []
if s == -2:
s = next(iter(self.graph))
s = list(self.graph)[0]
d.append(s)
visited.append(s)
while d:
@ -114,7 +114,7 @@ class DirectedGraph:
stack = []
visited = []
if s == -2:
s = next(iter(self.graph))
s = list(self.graph)[0]
stack.append(s)
visited.append(s)
ss = s
@ -146,7 +146,7 @@ class DirectedGraph:
def cycle_nodes(self):
stack = []
visited = []
s = next(iter(self.graph))
s = list(self.graph)[0]
stack.append(s)
visited.append(s)
parent = -2
@ -199,7 +199,7 @@ class DirectedGraph:
def has_cycle(self):
stack = []
visited = []
s = next(iter(self.graph))
s = list(self.graph)[0]
stack.append(s)
visited.append(s)
parent = -2
@ -305,7 +305,7 @@ class Graph:
stack = []
visited = []
if s == -2:
s = next(iter(self.graph))
s = list(self.graph)[0]
stack.append(s)
visited.append(s)
ss = s
@ -353,7 +353,7 @@ class Graph:
d = deque()
visited = []
if s == -2:
s = next(iter(self.graph))
s = list(self.graph)[0]
d.append(s)
visited.append(s)
while d:
@ -371,7 +371,7 @@ class Graph:
def cycle_nodes(self):
stack = []
visited = []
s = next(iter(self.graph))
s = list(self.graph)[0]
stack.append(s)
visited.append(s)
parent = -2
@ -424,7 +424,7 @@ class Graph:
def has_cycle(self):
stack = []
visited = []
s = next(iter(self.graph))
s = list(self.graph)[0]
stack.append(s)
visited.append(s)
parent = -2

View File

@ -113,7 +113,7 @@ class PushRelabelExecutor(MaximumFlowAlgorithmExecutor):
vertices_list = [
i
for i in range(self.verticies_count)
if i not in {self.source_index, self.sink_index}
if i != self.source_index and i != self.sink_index
]
# move through list

View File

@ -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 in {0, 1} else n * factorial(n - 1)
return 1 if n == 0 or n == 1 else n * factorial(n - 1)
if __name__ == "__main__":

View File

@ -154,7 +154,7 @@ def prime_factorization(number):
quotient = number
if number in {0, 1}:
if number == 0 or number == 1:
ans.append(number)
# if 'number' not prime then builds the prime factorization of 'number'

View File

@ -253,7 +253,7 @@ def find_unit_clauses(
unit_symbols = []
for clause in clauses:
if len(clause) == 1:
unit_symbols.append(next(iter(clause.literals.keys())))
unit_symbols.append(list(clause.literals.keys())[0])
else:
f_count, n_count = 0, 0
for literal, value in clause.literals.items():

View File

@ -1,6 +1,6 @@
"""
A number container system that uses binary search to delete and insert values into
arrays with O(log n) write times and O(1) read times.
arrays with O(n logn) write times and O(1) read times.
This container system holds integers at indexes.

View File

@ -28,16 +28,12 @@ def solution() -> int:
31875000
"""
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)
]
)
)
return [
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__":

View File

@ -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(next(iter(res.get_counts())), 2)
return int(list(res.get_counts())[0], 2)
if __name__ == "__main__":

View File

@ -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] in {"C", "R"}:
if ops[i][j][0] == "C" or ops[i][j][0] == "R":
seq = assemble_transformation(ops, i - 1, j - 1)
seq.append(ops[i][j])
return seq

View File

@ -90,7 +90,9 @@ def convert(number: int) -> str:
else:
addition = ""
if counter in placevalue:
if current != 0 and ((temp_num % 100) // 10) != 0:
if current == 0 and ((temp_num % 100) // 10) == 0:
addition = ""
else:
addition = placevalue[counter]
if ((temp_num % 100) // 10) == 1:
words = teens[current] + addition + words