[pre-commit.ci] pre-commit autoupdate (#9013)

* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.0.285 → v0.0.286](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.285...v0.0.286)
- [github.com/tox-dev/pyproject-fmt: 0.13.1 → 1.1.0](https://github.com/tox-dev/pyproject-fmt/compare/0.13.1...1.1.0)

* updating DIRECTORY.md

* Fis ruff rules PIE808,PLR1714

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
pre-commit-ci[bot] 2023-08-29 15:18:10 +02:00 committed by GitHub
parent 0a9438071e
commit 421ace81ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 70 additions and 71 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: auto-walrus
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.285
rev: v0.0.286
hooks:
- id: ruff
@ -33,7 +33,7 @@ repos:
- tomli
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "0.13.1"
rev: "1.1.0"
hooks:
- id: pyproject-fmt

View File

@ -245,7 +245,6 @@
* Stacks
* [Balanced Parentheses](data_structures/stacks/balanced_parentheses.py)
* [Dijkstras Two Stack Algorithm](data_structures/stacks/dijkstras_two_stack_algorithm.py)
* [Evaluate Postfix Notations](data_structures/stacks/evaluate_postfix_notations.py)
* [Infix To Postfix Conversion](data_structures/stacks/infix_to_postfix_conversion.py)
* [Infix To Prefix Conversion](data_structures/stacks/infix_to_prefix_conversion.py)
* [Next Greater Element](data_structures/stacks/next_greater_element.py)

View File

@ -152,9 +152,9 @@ def strictly_diagonally_dominant(table: NDArray[float64]) -> bool:
is_diagonally_dominant = True
for i in range(0, rows):
for i in range(rows):
total = 0
for j in range(0, cols - 1):
for j in range(cols - 1):
if i == j:
continue
else:

View File

@ -20,7 +20,7 @@ def secant_method(lower_bound: float, upper_bound: float, repeats: int) -> float
"""
x0 = lower_bound
x1 = upper_bound
for _ in range(0, repeats):
for _ in range(repeats):
x0, x1 = x1, x1 - (f(x1) * (x1 - x0)) / (f(x1) - f(x0))
return x1

View File

@ -95,7 +95,7 @@ def util_hamilton_cycle(graph: list[list[int]], path: list[int], curr_ind: int)
return graph[path[curr_ind - 1]][path[0]] == 1
# Recursive Step
for next_ver in range(0, len(graph)):
for next_ver in range(len(graph)):
if valid_connection(graph, next_ver, curr_ind, path):
# Insert current vertex into path as next transition
path[curr_ind] = next_ver

View File

@ -48,7 +48,7 @@ def is_safe(grid: Matrix, row: int, column: int, n: int) -> bool:
is found) else returns True if it is 'safe'
"""
for i in range(9):
if grid[row][i] == n or grid[i][column] == n:
if n in {grid[row][i], grid[i][column]}:
return False
for i in range(3):

View File

@ -20,7 +20,7 @@ def get_reverse_bit_string(number: int) -> str:
)
raise TypeError(msg)
bit_string = ""
for _ in range(0, 32):
for _ in range(32):
bit_string += str(number % 2)
number = number >> 1
return bit_string

View File

@ -119,7 +119,7 @@ def decrypt_message(
for i in range(0, len(message) + 1, period):
a, b, c = __decrypt_part(message[i : i + period], character_to_number)
for j in range(0, len(a)):
for j in range(len(a)):
decrypted_numeric.append(a[j] + b[j] + c[j])
for each in decrypted_numeric:

View File

@ -7,10 +7,10 @@ class SegmentTree:
def __init__(self, size: int) -> None:
self.size = size
# approximate the overall size of segment tree with given value
self.segment_tree = [0 for i in range(0, 4 * size)]
self.segment_tree = [0 for i in range(4 * size)]
# create array to store lazy update
self.lazy = [0 for i in range(0, 4 * size)]
self.flag = [0 for i in range(0, 4 * size)] # flag for lazy update
self.lazy = [0 for i in range(4 * size)]
self.flag = [0 for i in range(4 * size)] # flag for lazy update
def left(self, idx: int) -> int:
"""

View File

@ -125,7 +125,7 @@ def test_circular_linked_list() -> None:
circular_linked_list.insert_tail(6)
assert str(circular_linked_list) == "->".join(str(i) for i in range(1, 7))
circular_linked_list.insert_head(0)
assert str(circular_linked_list) == "->".join(str(i) for i in range(0, 7))
assert str(circular_linked_list) == "->".join(str(i) for i in range(7))
assert circular_linked_list.delete_front() == 0
assert circular_linked_list.delete_tail() == 6

View File

@ -98,7 +98,7 @@ class DoublyLinkedList:
self.tail = new_node
else:
temp = self.head
for _ in range(0, index):
for _ in range(index):
temp = temp.next
temp.previous.next = new_node
new_node.previous = temp.previous
@ -149,7 +149,7 @@ class DoublyLinkedList:
self.tail.next = None
else:
temp = self.head
for _ in range(0, index):
for _ in range(index):
temp = temp.next
delete_node = temp
temp.next.previous = temp.previous
@ -215,7 +215,7 @@ def test_doubly_linked_list() -> None:
linked_list.insert_at_head(0)
linked_list.insert_at_tail(11)
assert str(linked_list) == "->".join(str(i) for i in range(0, 12))
assert str(linked_list) == "->".join(str(i) for i in range(12))
assert linked_list.delete_head() == 0
assert linked_list.delete_at_nth(9) == 10

View File

@ -68,7 +68,7 @@ def is_palindrome_dict(head):
middle += 1
else:
step = 0
for i in range(0, len(v)):
for i in range(len(v)):
if v[i] + v[len(v) - 1 - step] != checksum:
return False
step += 1

View File

@ -370,7 +370,7 @@ def test_singly_linked_list() -> None:
linked_list.insert_head(0)
linked_list.insert_tail(11)
assert str(linked_list) == "->".join(str(i) for i in range(0, 12))
assert str(linked_list) == "->".join(str(i) for i in range(12))
assert linked_list.delete_head() == 0
assert linked_list.delete_nth(9) == 10
@ -378,11 +378,11 @@ def test_singly_linked_list() -> None:
assert len(linked_list) == 9
assert str(linked_list) == "->".join(str(i) for i in range(1, 10))
assert all(linked_list[i] == i + 1 for i in range(0, 9)) is True
assert all(linked_list[i] == i + 1 for i in range(9)) is True
for i in range(0, 9):
for i in range(9):
linked_list[i] = -i
assert all(linked_list[i] == -i for i in range(0, 9)) is True
assert all(linked_list[i] == -i for i in range(9)) is True
linked_list.reverse()
assert str(linked_list) == "->".join(str(i) for i in range(-8, 1))

View File

@ -36,7 +36,7 @@ def calculation_span(price, s):
# A utility function to print elements of array
def print_array(arr, n):
for i in range(0, n):
for i in range(n):
print(arr[i], end=" ")

View File

@ -31,8 +31,8 @@ def get_slice(img: np.ndarray, x: int, y: int, kernel_size: int) -> np.ndarray:
def get_gauss_kernel(kernel_size: int, spatial_variance: float) -> np.ndarray:
# Creates a gaussian kernel of given dimension.
arr = np.zeros((kernel_size, kernel_size))
for i in range(0, kernel_size):
for j in range(0, kernel_size):
for i in range(kernel_size):
for j in range(kernel_size):
arr[i, j] = math.sqrt(
abs(i - kernel_size // 2) ** 2 + abs(j - kernel_size // 2) ** 2
)

View File

@ -11,8 +11,8 @@ def im2col(image, block_size):
dst_width = rows - block_size[0] + 1
image_array = zeros((dst_height * dst_width, block_size[1] * block_size[0]))
row = 0
for i in range(0, dst_height):
for j in range(0, dst_width):
for i in range(dst_height):
for j in range(dst_width):
window = ravel(image[i : i + block_size[0], j : j + block_size[1]])
image_array[row, :] = window
row += 1

View File

@ -71,8 +71,8 @@ if __name__ == "__main__":
# Iterating through the image and calculating the
# local binary pattern value for each pixel.
for i in range(0, image.shape[0]):
for j in range(0, image.shape[1]):
for i in range(image.shape[0]):
for j in range(image.shape[1]):
lbp_image[i][j] = local_binary_value(image, i, j)
cv2.imshow("local binary pattern", lbp_image)

View File

@ -118,8 +118,8 @@ def test_local_binary_pattern():
# Iterating through the image and calculating the local binary pattern value
# for each pixel.
for i in range(0, image.shape[0]):
for j in range(0, image.shape[1]):
for i in range(image.shape[0]):
for j in range(image.shape[1]):
lbp_image[i][j] = lbp.local_binary_value(image, i, j)
assert lbp_image.any()

View File

@ -131,7 +131,7 @@ def strassen(matrix1: list, matrix2: list) -> list:
# Adding zeros to the matrices so that the arrays dimensions are the same and also
# power of 2
for i in range(0, maxim):
for i in range(maxim):
if i < dimension1[0]:
for _ in range(dimension1[1], maxim):
new_matrix1[i].append(0)
@ -146,7 +146,7 @@ def strassen(matrix1: list, matrix2: list) -> list:
final_matrix = actual_strassen(new_matrix1, new_matrix2)
# Removing the additional zeros
for i in range(0, maxim):
for i in range(maxim):
if i < dimension1[0]:
for _ in range(dimension2[1], maxim):
final_matrix[i].pop()

View File

@ -5,19 +5,19 @@ class Graph:
def __init__(self, n=0): # a graph with Node 0,1,...,N-1
self.n = n
self.w = [
[math.inf for j in range(0, n)] for i in range(0, n)
[math.inf for j in range(n)] for i in range(n)
] # adjacency matrix for weight
self.dp = [
[math.inf for j in range(0, n)] for i in range(0, n)
[math.inf for j in range(n)] for i in range(n)
] # dp[i][j] stores minimum distance from i to j
def add_edge(self, u, v, w):
self.dp[u][v] = w
def floyd_warshall(self):
for k in range(0, self.n):
for i in range(0, self.n):
for j in range(0, self.n):
for k in range(self.n):
for i in range(self.n):
for j in range(self.n):
self.dp[i][j] = min(self.dp[i][j], self.dp[i][k] + self.dp[k][j])
def show_min(self, u, v):

View File

@ -53,7 +53,7 @@ def pull():
key = machine_time % m
# Evolution (Time Length)
for _ in range(0, t):
for _ in range(t):
# Variables (Position + Parameters)
r = params_space[key]
value = buffer_space[key]

View File

@ -135,7 +135,7 @@ def emitter_converter(size_par, data):
# Mount the message
cont_bp = 0 # parity bit counter
for x in range(0, size_par + len(data)):
for x in range(size_par + len(data)):
if data_ord[x] is None:
data_out.append(str(parity[cont_bp]))
cont_bp += 1
@ -228,7 +228,7 @@ def receptor_converter(size_par, data):
# Mount the message
cont_bp = 0 # Parity bit counter
for x in range(0, size_par + len(data_output)):
for x in range(size_par + len(data_output)):
if data_ord[x] is None:
data_out.append(str(parity[cont_bp]))
cont_bp += 1

View File

@ -97,7 +97,7 @@ class SHA1Hash:
for block in self.blocks:
expanded_block = self.expand_block(block)
a, b, c, d, e = self.h
for i in range(0, 80):
for i in range(80):
if 0 <= i < 20:
f = (b & c) | ((~b) & d)
k = 0x5A827999

View File

@ -138,7 +138,7 @@ class SHA256:
a, b, c, d, e, f, g, h = self.hashes
for index in range(0, 64):
for index in range(64):
if index > 15:
# modify the zero-ed indexes at the end of the array
s0 = (

View File

@ -110,7 +110,7 @@ def run_gradient_descent():
while True:
j += 1
temp_parameter_vector = [0, 0, 0, 0]
for i in range(0, len(parameter_vector)):
for i in range(len(parameter_vector)):
cost_derivative = get_cost_derivative(i - 1)
temp_parameter_vector[i] = (
parameter_vector[i] - LEARNING_RATE * cost_derivative

View File

@ -78,7 +78,7 @@ def run_linear_regression(data_x, data_y):
theta = np.zeros((1, no_features))
for i in range(0, iterations):
for i in range(iterations):
theta = run_steep_gradient_descent(data_x, data_y, len_data, alpha, theta)
error = sum_of_square_error(data_x, data_y, len_data, theta)
print(f"At Iteration {i + 1} - Error is {error:.5f}")
@ -107,7 +107,7 @@ def main():
theta = run_linear_regression(data_x, data_y)
len_result = theta.shape[1]
print("Resultant Feature vector : ")
for i in range(0, len_result):
for i in range(len_result):
print(f"{theta[0, i]:.5f}")

View File

@ -32,10 +32,10 @@ if __name__ == "__main__":
train_x, train_y = [], []
test_x, test_y = [], []
for i in range(0, len(train_data) - forward_days - look_back + 1):
for i in range(len(train_data) - forward_days - look_back + 1):
train_x.append(train_data[i : i + look_back])
train_y.append(train_data[i + look_back : i + look_back + forward_days])
for i in range(0, len(test_data) - forward_days - look_back + 1):
for i in range(len(test_data) - forward_days - look_back + 1):
test_x.append(test_data[i : i + look_back])
test_y.append(test_data[i + look_back : i + look_back + forward_days])
x_train = np.array(train_x)

View File

@ -101,7 +101,7 @@ def analyze_text(text: str) -> tuple[dict, dict]:
# first case when we have space at start.
two_char_strings[" " + text[0]] += 1
for i in range(0, len(text) - 1):
for i in range(len(text) - 1):
single_char_strings[text[i]] += 1
two_char_strings[text[i : i + 2]] += 1
return single_char_strings, two_char_strings

View File

@ -21,7 +21,7 @@ def totient(n: int) -> list:
for i in range(2, n + 1):
if is_prime[i]:
primes.append(i)
for j in range(0, len(primes)):
for j in range(len(primes)):
if i * primes[j] >= n:
break
is_prime[i * primes[j]] = False

View File

@ -81,7 +81,7 @@ if __name__ == "__main__":
):
n = int(input("Enter the number of denominations you want to add: ").strip())
for i in range(0, n):
for i in range(n):
denominations.append(int(input(f"Denomination {i}: ").strip()))
value = input("Enter the change you want to make in Indian Currency: ").strip()
else:

View File

@ -28,7 +28,7 @@ def multiplicative_persistence(num: int) -> int:
numbers = [int(i) for i in num_string]
total = 1
for i in range(0, len(numbers)):
for i in range(len(numbers)):
total *= numbers[i]
num_string = str(total)
@ -67,7 +67,7 @@ def additive_persistence(num: int) -> int:
numbers = [int(i) for i in num_string]
total = 0
for i in range(0, len(numbers)):
for i in range(len(numbers)):
total += numbers[i]
num_string = str(total)

View File

@ -45,7 +45,7 @@ def is_harmonic_series(series: list) -> bool:
return True
rec_series = []
series_len = len(series)
for i in range(0, series_len):
for i in range(series_len):
if series[i] == 0:
raise ValueError("Input series cannot have 0 as an element")
rec_series.append(1 / series[i])

View File

@ -54,7 +54,7 @@ def spiral_print_clockwise(a: list[list[int]]) -> None:
return
# horizotal printing increasing
for i in range(0, mat_col):
for i in range(mat_col):
print(a[0][i])
# vertical printing down
for i in range(1, mat_row):

View File

@ -7,10 +7,10 @@ def floyd(n):
Parameters:
n : size of pattern
"""
for i in range(0, n):
for _ in range(0, n - i - 1): # printing spaces
for i in range(n):
for _ in range(n - i - 1): # printing spaces
print(" ", end="")
for _ in range(0, i + 1): # printing stars
for _ in range(i + 1): # printing stars
print("* ", end="")
print()

View File

@ -44,7 +44,7 @@ def get_totients(max_one: int) -> list[int]:
"""
totients = [0] * max_one
for i in range(0, max_one):
for i in range(max_one):
totients[i] = i
for i in range(2, max_one):

View File

@ -49,7 +49,7 @@ def check_bouncy(n: int) -> bool:
raise ValueError("check_bouncy() accepts only integer arguments")
str_n = str(n)
sorted_str_n = "".join(sorted(str_n))
return sorted_str_n != str_n and sorted_str_n[::-1] != str_n
return str_n not in {sorted_str_n, sorted_str_n[::-1]}
def solution(percent: float = 99) -> int:

View File

@ -88,7 +88,7 @@ def quantum_full_adder(
quantum_circuit = qiskit.QuantumCircuit(qr, cr)
for i in range(0, 3):
for i in range(3):
if entry[i] == 2:
quantum_circuit.h(i) # for hadamard entries
elif entry[i] == 1:

View File

@ -53,7 +53,7 @@ def calculate_turn_around_time(
loc = 0
# Saves the current response ratio.
temp = 0
for i in range(0, no_of_process):
for i in range(no_of_process):
if finished_process[i] == 0 and arrival_time[i] <= current_time:
temp = (burst_time[i] + (current_time - arrival_time[i])) / burst_time[
i
@ -87,7 +87,7 @@ def calculate_waiting_time(
"""
waiting_time = [0] * no_of_process
for i in range(0, no_of_process):
for i in range(no_of_process):
waiting_time[i] = turn_around_time[i] - burst_time[i]
return waiting_time
@ -106,7 +106,7 @@ if __name__ == "__main__":
)
print("Process name \tArrival time \tBurst time \tTurn around time \tWaiting time")
for i in range(0, no_of_process):
for i in range(no_of_process):
print(
f"{process_name[i]}\t\t{arrival_time[i]}\t\t{burst_time[i]}\t\t"
f"{turn_around_time[i]}\t\t\t{waiting_time[i]}"

View File

@ -49,7 +49,7 @@ def counting_sort(collection):
# place the elements in the output, respecting the original order (stable
# sort) from end to begin, updating counting_arr
for i in reversed(range(0, coll_len)):
for i in reversed(range(coll_len)):
ordered[counting_arr[collection[i] - coll_min] - 1] = collection[i]
counting_arr[collection[i] - coll_min] -= 1

View File

@ -19,7 +19,7 @@ def cycle_sort(array: list) -> list:
[]
"""
array_len = len(array)
for cycle_start in range(0, array_len - 1):
for cycle_start in range(array_len - 1):
item = array[cycle_start]
pos = cycle_start

View File

@ -16,9 +16,9 @@ def double_sort(lst):
"""
no_of_elements = len(lst)
for _ in range(
0, int(((no_of_elements - 1) / 2) + 1)
int(((no_of_elements - 1) / 2) + 1)
): # we don't need to traverse to end of list as
for j in range(0, no_of_elements - 1):
for j in range(no_of_elements - 1):
if (
lst[j + 1] < lst[j]
): # applying bubble sort algorithm from left to right (or forwards)

View File

@ -33,7 +33,7 @@ def oe_process(position, value, l_send, r_send, lr_cv, rr_cv, result_pipe):
# we perform n swaps since after n swaps we know we are sorted
# we *could* stop early if we are sorted already, but it takes as long to
# find out we are sorted as it does to sort the list with this algorithm
for i in range(0, 10):
for i in range(10):
if (i + position) % 2 == 0 and r_send is not None:
# send your value to your right neighbor
process_lock.acquire()
@ -123,7 +123,7 @@ def odd_even_transposition(arr):
p.start()
# wait for the processes to end and write their values to the list
for p in range(0, len(result_pipe)):
for p in range(len(result_pipe)):
arr[p] = result_pipe[p][0].recv()
process_array_[p].join()
return arr

View File

@ -38,7 +38,7 @@ def rabin_karp(pattern: str, text: str) -> bool:
continue
modulus_power = (modulus_power * alphabet_size) % modulus
for i in range(0, t_len - p_len + 1):
for i in range(t_len - p_len + 1):
if text_hash == p_hash and text[i : i + p_len] == pattern:
return True
if i == t_len - p_len: