mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
Add flake8 pluin flake8 bugbear to pre-commit (#7132)
* ci(pre-commit): Add ``flake8-builtins`` additional dependency to ``pre-commit`` (#7104) * refactor: Fix ``flake8-builtins`` (#7104) * fix(lru_cache): Fix naming conventions in docstrings (#7104) * ci(pre-commit): Order additional dependencies alphabetically (#7104) * fix(lfu_cache): Correct function name in docstring (#7104) * Update strings/snake_case_to_camel_pascal_case.py Co-authored-by: Christian Clauss <cclauss@me.com> * Update data_structures/stacks/next_greater_element.py Co-authored-by: Christian Clauss <cclauss@me.com> * Update digital_image_processing/index_calculation.py Co-authored-by: Christian Clauss <cclauss@me.com> * Update graphs/prim.py Co-authored-by: Christian Clauss <cclauss@me.com> * Update hashes/djb2.py Co-authored-by: Christian Clauss <cclauss@me.com> * refactor: Rename `_builtin` to `builtin_` ( #7104) * fix: Rename all instances (#7104) * refactor: Update variable names (#7104) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * ci: Create ``tox.ini`` and ignore ``A003`` (#7123) * revert: Remove function name changes (#7104) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Rename tox.ini to .flake8 * Update data_structures/heap/heap.py Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com> * refactor: Rename `next_` to `next_item` (#7104) * ci(pre-commit): Add `flake8` plugin `flake8-bugbear` (#7127) * refactor: Follow `flake8-bugbear` plugin (#7127) * fix: Correct `knapsack` code (#7127) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: Christian Clauss <cclauss@me.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
This commit is contained in:
@ -35,7 +35,7 @@ def trapezoidal_area(
|
||||
x1 = x_start
|
||||
fx1 = fnc(x_start)
|
||||
area = 0.0
|
||||
for i in range(steps):
|
||||
for _ in range(steps):
|
||||
# Approximates small segments of curve as linear and solve
|
||||
# for trapezoidal area
|
||||
x2 = (x_end - x_start) / steps + x1
|
||||
|
@ -40,7 +40,7 @@ def line_length(
|
||||
fx1 = fnc(x_start)
|
||||
length = 0.0
|
||||
|
||||
for i in range(steps):
|
||||
for _ in range(steps):
|
||||
|
||||
# Approximates curve as a sequence of linear lines and sums their length
|
||||
x2 = (x_end - x_start) / steps + x1
|
||||
|
@ -31,7 +31,7 @@ def lucas_lehmer_test(p: int) -> bool:
|
||||
|
||||
s = 4
|
||||
m = (1 << p) - 1
|
||||
for i in range(p - 2):
|
||||
for _ in range(p - 2):
|
||||
s = ((s * s) - 2) % m
|
||||
return s == 0
|
||||
|
||||
|
@ -50,7 +50,7 @@ def dynamic_lucas_number(n_th_number: int) -> int:
|
||||
if not isinstance(n_th_number, int):
|
||||
raise TypeError("dynamic_lucas_number accepts only integer arguments.")
|
||||
a, b = 2, 1
|
||||
for i in range(n_th_number):
|
||||
for _ in range(n_th_number):
|
||||
a, b = b, a + b
|
||||
return a
|
||||
|
||||
|
@ -33,7 +33,7 @@ def is_prime_big(n, prec=1000):
|
||||
b = bin_exp_mod(a, d, n)
|
||||
if b != 1:
|
||||
flag = True
|
||||
for i in range(exp):
|
||||
for _ in range(exp):
|
||||
if b == n - 1:
|
||||
flag = False
|
||||
break
|
||||
|
@ -35,7 +35,7 @@ def throw_dice(num_throws: int, num_dice: int = 2) -> list[float]:
|
||||
"""
|
||||
dices = [Dice() for i in range(num_dice)]
|
||||
count_of_sum = [0] * (len(dices) * Dice.NUM_SIDES + 1)
|
||||
for i in range(num_throws):
|
||||
for _ in range(num_throws):
|
||||
count_of_sum[sum(dice.roll() for dice in dices)] += 1
|
||||
probability = [round((count * 100) / num_throws, 2) for count in count_of_sum]
|
||||
return probability[num_dice:] # remove probability of sums that never appear
|
||||
|
@ -39,7 +39,7 @@ def trapezoidal_area(
|
||||
fx1 = fnc(x_start)
|
||||
area = 0.0
|
||||
|
||||
for i in range(steps):
|
||||
for _ in range(steps):
|
||||
|
||||
# Approximates small segments of curve as linear and solve
|
||||
# for trapezoidal area
|
||||
|
@ -47,7 +47,7 @@ def estimate_pi(number_of_simulations: int) -> float:
|
||||
raise ValueError("At least one simulation is necessary to estimate PI.")
|
||||
|
||||
number_in_unit_circle = 0
|
||||
for simulation_index in range(number_of_simulations):
|
||||
for _ in range(number_of_simulations):
|
||||
random_point = Point.random_unit_square()
|
||||
|
||||
if random_point.is_in_unit_circle():
|
||||
|
@ -73,7 +73,7 @@ def pollard_rho(
|
||||
"""
|
||||
return (pow(value, 2) + step) % modulus
|
||||
|
||||
for attempt in range(attempts):
|
||||
for _ in range(attempts):
|
||||
# These track the position within the cycle detection logic.
|
||||
tortoise = seed
|
||||
hare = seed
|
||||
|
@ -406,14 +406,14 @@ def kg_v(number1, number2):
|
||||
count1 = prime_fac_1.count(n)
|
||||
count2 = prime_fac_2.count(n)
|
||||
|
||||
for i in range(max(count1, count2)):
|
||||
for _ in range(max(count1, count2)):
|
||||
ans *= n
|
||||
|
||||
else:
|
||||
|
||||
count1 = prime_fac_1.count(n)
|
||||
|
||||
for i in range(count1):
|
||||
for _ in range(count1):
|
||||
ans *= n
|
||||
|
||||
done.append(n)
|
||||
@ -425,7 +425,7 @@ def kg_v(number1, number2):
|
||||
|
||||
count2 = prime_fac_2.count(n)
|
||||
|
||||
for i in range(count2):
|
||||
for _ in range(count2):
|
||||
ans *= n
|
||||
|
||||
done.append(n)
|
||||
@ -637,7 +637,7 @@ def fib(n):
|
||||
fib1 = 1
|
||||
ans = 1 # this will be return
|
||||
|
||||
for i in range(n - 1):
|
||||
for _ in range(n - 1):
|
||||
|
||||
tmp = ans
|
||||
ans += fib1
|
||||
|
@ -49,7 +49,7 @@ def proth(number: int) -> int:
|
||||
proth_index = 2
|
||||
increment = 3
|
||||
for block in range(1, block_index):
|
||||
for move in range(increment):
|
||||
for _ in range(increment):
|
||||
proth_list.append(2 ** (block + 1) + proth_list[proth_index - 1])
|
||||
proth_index += 1
|
||||
increment *= 2
|
||||
|
@ -49,7 +49,7 @@ def square_root_iterative(
|
||||
|
||||
value = get_initial_point(a)
|
||||
|
||||
for i in range(max_iter):
|
||||
for _ in range(max_iter):
|
||||
prev_value = value
|
||||
value = value - fx(value, a) / fx_derivative(value)
|
||||
if abs(prev_value - value) < tolerance:
|
||||
|
@ -32,7 +32,7 @@ def ugly_numbers(n: int) -> int:
|
||||
next_3 = ugly_nums[i3] * 3
|
||||
next_5 = ugly_nums[i5] * 5
|
||||
|
||||
for i in range(1, n):
|
||||
for _ in range(1, n):
|
||||
next_num = min(next_2, next_3, next_5)
|
||||
ugly_nums.append(next_num)
|
||||
if next_num == next_2:
|
||||
|
Reference in New Issue
Block a user