Skip to content

Commit d5a9f64

Browse files
CaedenPHcclausspre-commit-ci[bot]dhruvmanila
authoredOct 13, 2022
Add flake8-builtins to pre-commit and fix errors (TheAlgorithms#7105)
Ignore `A003` Co-authored-by: Christian Clauss <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Dhruv Manilawala <[email protected]>
1 parent e661b98 commit d5a9f64

31 files changed

+113
-106
lines changed
 

‎.flake8

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
extend-ignore =
3+
A003 # Class attribute is shadowing a python builtin

‎.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ repos:
4040
- --ignore=E203,W503
4141
- --max-complexity=25
4242
- --max-line-length=88
43-
additional_dependencies: [pep8-naming]
43+
additional_dependencies: [flake8-builtins, pep8-naming]
4444

4545
- repo: https://github.com/pre-commit/mirrors-mypy
4646
rev: v0.982

‎arithmetic_analysis/gaussian_elimination.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ def retroactive_resolution(
3333

3434
x: NDArray[float64] = np.zeros((rows, 1), dtype=float)
3535
for row in reversed(range(rows)):
36-
sum = 0
36+
total = 0
3737
for col in range(row + 1, columns):
38-
sum += coefficients[row, col] * x[col]
38+
total += coefficients[row, col] * x[col]
3939

40-
x[row, 0] = (vector[row] - sum) / coefficients[row, row]
40+
x[row, 0] = (vector[row] - total) / coefficients[row, row]
4141

4242
return x
4343

‎arithmetic_analysis/jacobi_iteration_method.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ def strictly_diagonally_dominant(table: NDArray[float64]) -> bool:
147147
is_diagonally_dominant = True
148148

149149
for i in range(0, rows):
150-
sum = 0
150+
total = 0
151151
for j in range(0, cols - 1):
152152
if i == j:
153153
continue
154154
else:
155-
sum += table[i][j]
155+
total += table[i][j]
156156

157-
if table[i][i] <= sum:
157+
if table[i][i] <= total:
158158
raise ValueError("Coefficient matrix is not strictly diagonally dominant")
159159

160160
return is_diagonally_dominant

‎audio_filters/show_response.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_bounds(
3434
return lowest, highest
3535

3636

37-
def show_frequency_response(filter: FilterType, samplerate: int) -> None:
37+
def show_frequency_response(filter_type: FilterType, samplerate: int) -> None:
3838
"""
3939
Show frequency response of a filter
4040
@@ -45,7 +45,7 @@ def show_frequency_response(filter: FilterType, samplerate: int) -> None:
4545

4646
size = 512
4747
inputs = [1] + [0] * (size - 1)
48-
outputs = [filter.process(item) for item in inputs]
48+
outputs = [filter_type.process(item) for item in inputs]
4949

5050
filler = [0] * (samplerate - size) # zero-padding
5151
outputs += filler
@@ -66,7 +66,7 @@ def show_frequency_response(filter: FilterType, samplerate: int) -> None:
6666
plt.show()
6767

6868

69-
def show_phase_response(filter: FilterType, samplerate: int) -> None:
69+
def show_phase_response(filter_type: FilterType, samplerate: int) -> None:
7070
"""
7171
Show phase response of a filter
7272
@@ -77,7 +77,7 @@ def show_phase_response(filter: FilterType, samplerate: int) -> None:
7777

7878
size = 512
7979
inputs = [1] + [0] * (size - 1)
80-
outputs = [filter.process(item) for item in inputs]
80+
outputs = [filter_type.process(item) for item in inputs]
8181

8282
filler = [0] * (samplerate - size) # zero-padding
8383
outputs += filler

‎backtracking/hamiltonian_cycle.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ def util_hamilton_cycle(graph: list[list[int]], path: list[int], curr_ind: int)
9595
return graph[path[curr_ind - 1]][path[0]] == 1
9696

9797
# Recursive Step
98-
for next in range(0, len(graph)):
99-
if valid_connection(graph, next, curr_ind, path):
98+
for next_ver in range(0, len(graph)):
99+
if valid_connection(graph, next_ver, curr_ind, path):
100100
# Insert current vertex into path as next transition
101-
path[curr_ind] = next
101+
path[curr_ind] = next_ver
102102
# Validate created path
103103
if util_hamilton_cycle(graph, path, curr_ind + 1):
104104
return True

‎data_structures/binary_tree/avl_tree.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def pop(self) -> Any:
3333
def count(self) -> int:
3434
return self.tail - self.head
3535

36-
def print(self) -> None:
36+
def print_queue(self) -> None:
3737
print(self.data)
3838
print("**************")
3939
print(self.data[self.head : self.tail])

‎data_structures/linked_list/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
class Node:
14-
def __init__(self, item: Any, next: Any) -> None:
14+
def __init__(self, item: Any, next: Any) -> None: # noqa: A002
1515
self.item = item
1616
self.next = next
1717

‎data_structures/linked_list/singly_linked_list.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def test_singly_linked_list_2() -> None:
392392
This section of the test used varying data types for input.
393393
>>> test_singly_linked_list_2()
394394
"""
395-
input = [
395+
test_input = [
396396
-9,
397397
100,
398398
Node(77345112),
@@ -410,7 +410,7 @@ def test_singly_linked_list_2() -> None:
410410
]
411411
linked_list = LinkedList()
412412

413-
for i in input:
413+
for i in test_input:
414414
linked_list.insert_tail(i)
415415

416416
# Check if it's empty or not

‎data_structures/queue/double_ended_queue.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ class Deque:
1515
----------
1616
append(val: Any) -> None
1717
appendleft(val: Any) -> None
18-
extend(iter: Iterable) -> None
19-
extendleft(iter: Iterable) -> None
18+
extend(iterable: Iterable) -> None
19+
extendleft(iterable: Iterable) -> None
2020
pop() -> Any
2121
popleft() -> Any
2222
Observers
@@ -179,9 +179,9 @@ def appendleft(self, val: Any) -> None:
179179
# make sure there were no errors
180180
assert not self.is_empty(), "Error on appending value."
181181

182-
def extend(self, iter: Iterable[Any]) -> None:
182+
def extend(self, iterable: Iterable[Any]) -> None:
183183
"""
184-
Appends every value of iter to the end of the deque.
184+
Appends every value of iterable to the end of the deque.
185185
Time complexity: O(n)
186186
>>> our_deque_1 = Deque([1, 2, 3])
187187
>>> our_deque_1.extend([4, 5])
@@ -205,12 +205,12 @@ def extend(self, iter: Iterable[Any]) -> None:
205205
>>> list(our_deque_2) == list(deque_collections_2)
206206
True
207207
"""
208-
for val in iter:
208+
for val in iterable:
209209
self.append(val)
210210

211-
def extendleft(self, iter: Iterable[Any]) -> None:
211+
def extendleft(self, iterable: Iterable[Any]) -> None:
212212
"""
213-
Appends every value of iter to the beginning of the deque.
213+
Appends every value of iterable to the beginning of the deque.
214214
Time complexity: O(n)
215215
>>> our_deque_1 = Deque([1, 2, 3])
216216
>>> our_deque_1.extendleft([0, -1])
@@ -234,7 +234,7 @@ def extendleft(self, iter: Iterable[Any]) -> None:
234234
>>> list(our_deque_2) == list(deque_collections_2)
235235
True
236236
"""
237-
for val in iter:
237+
for val in iterable:
238238
self.appendleft(val)
239239

240240
def pop(self) -> Any:

‎data_structures/stacks/next_greater_element.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ def next_greatest_element_slow(arr: list[float]) -> list[float]:
1717
arr_size = len(arr)
1818

1919
for i in range(arr_size):
20-
next: float = -1
20+
next_element: float = -1
2121
for j in range(i + 1, arr_size):
2222
if arr[i] < arr[j]:
23-
next = arr[j]
23+
next_element = arr[j]
2424
break
25-
result.append(next)
25+
result.append(next_element)
2626
return result
2727

2828

@@ -36,12 +36,12 @@ def next_greatest_element_fast(arr: list[float]) -> list[float]:
3636
"""
3737
result = []
3838
for i, outer in enumerate(arr):
39-
next: float = -1
39+
next_item: float = -1
4040
for inner in arr[i + 1 :]:
4141
if outer < inner:
42-
next = inner
42+
next_item = inner
4343
break
44-
result.append(next)
44+
result.append(next_item)
4545
return result
4646

4747

‎digital_image_processing/index_calculation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,9 @@ def s(self):
497497
https://www.indexdatabase.de/db/i-single.php?id=77
498498
:return: index
499499
"""
500-
max = np.max([np.max(self.red), np.max(self.green), np.max(self.blue)])
501-
min = np.min([np.min(self.red), np.min(self.green), np.min(self.blue)])
502-
return (max - min) / max
500+
max_value = np.max([np.max(self.red), np.max(self.green), np.max(self.blue)])
501+
min_value = np.min([np.min(self.red), np.min(self.green), np.min(self.blue)])
502+
return (max_value - min_value) / max_value
503503

504504
def _if(self):
505505
"""

‎dynamic_programming/optimal_binary_search_tree.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def find_optimal_binary_search_tree(nodes):
104104
dp = [[freqs[i] if i == j else 0 for j in range(n)] for i in range(n)]
105105
# sum[i][j] stores the sum of key frequencies between i and j inclusive in nodes
106106
# array
107-
sum = [[freqs[i] if i == j else 0 for j in range(n)] for i in range(n)]
107+
total = [[freqs[i] if i == j else 0 for j in range(n)] for i in range(n)]
108108
# stores tree roots that will be used later for constructing binary search tree
109109
root = [[i if i == j else 0 for j in range(n)] for i in range(n)]
110110

@@ -113,14 +113,14 @@ def find_optimal_binary_search_tree(nodes):
113113
j = i + interval_length - 1
114114

115115
dp[i][j] = sys.maxsize # set the value to "infinity"
116-
sum[i][j] = sum[i][j - 1] + freqs[j]
116+
total[i][j] = total[i][j - 1] + freqs[j]
117117

118118
# Apply Knuth's optimization
119119
# Loop without optimization: for r in range(i, j + 1):
120120
for r in range(root[i][j - 1], root[i + 1][j] + 1): # r is a temporal root
121121
left = dp[i][r - 1] if r != i else 0 # optimal cost for left subtree
122122
right = dp[r + 1][j] if r != j else 0 # optimal cost for right subtree
123-
cost = left + sum[i][j] + right
123+
cost = left + total[i][j] + right
124124

125125
if dp[i][j] > cost:
126126
dp[i][j] = cost

‎graphs/a_star.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ def search(
4040
else: # to choose the least costliest action so as to move closer to the goal
4141
cell.sort()
4242
cell.reverse()
43-
next = cell.pop()
44-
x = next[2]
45-
y = next[3]
46-
g = next[1]
43+
next_cell = cell.pop()
44+
x = next_cell[2]
45+
y = next_cell[3]
46+
g = next_cell[1]
4747

4848
if x == goal[0] and y == goal[1]:
4949
found = True

‎graphs/dijkstra.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ def dijkstra(graph, start, end):
5656
for v, c in graph[u]:
5757
if v in visited:
5858
continue
59-
next = cost + c
60-
heapq.heappush(heap, (next, v))
59+
next_item = cost + c
60+
heapq.heappush(heap, (next_item, v))
6161
return -1
6262

6363

‎graphs/finding_bridges.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,22 @@ def compute_bridges(graph: dict[int, list[int]]) -> list[tuple[int, int]]:
7272
[]
7373
"""
7474

75-
id = 0
75+
id_ = 0
7676
n = len(graph) # No of vertices in graph
7777
low = [0] * n
7878
visited = [False] * n
7979

80-
def dfs(at, parent, bridges, id):
80+
def dfs(at, parent, bridges, id_):
8181
visited[at] = True
82-
low[at] = id
83-
id += 1
82+
low[at] = id_
83+
id_ += 1
8484
for to in graph[at]:
8585
if to == parent:
8686
pass
8787
elif not visited[to]:
88-
dfs(to, at, bridges, id)
88+
dfs(to, at, bridges, id_)
8989
low[at] = min(low[at], low[to])
90-
if id <= low[to]:
90+
if id_ <= low[to]:
9191
bridges.append((at, to) if at < to else (to, at))
9292
else:
9393
# This edge is a back edge and cannot be a bridge
@@ -96,7 +96,7 @@ def dfs(at, parent, bridges, id):
9696
bridges: list[tuple[int, int]] = []
9797
for i in range(n):
9898
if not visited[i]:
99-
dfs(i, -1, bridges, id)
99+
dfs(i, -1, bridges, id_)
100100
return bridges
101101

102102

‎graphs/prim.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
class Vertex:
1414
"""Class Vertex."""
1515

16-
def __init__(self, id):
16+
def __init__(self, id_):
1717
"""
1818
Arguments:
1919
id - input an id to identify the vertex
2020
Attributes:
2121
neighbors - a list of the vertices it is linked to
2222
edges - a dict to store the edges's weight
2323
"""
24-
self.id = str(id)
24+
self.id = str(id_)
2525
self.key = None
2626
self.pi = None
2727
self.neighbors = []

‎hashes/djb2.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def djb2(s: str) -> int:
2929
>>> djb2('scramble bits')
3030
1609059040
3131
"""
32-
hash = 5381
32+
hash_value = 5381
3333
for x in s:
34-
hash = ((hash << 5) + hash) + ord(x)
35-
return hash & 0xFFFFFFFF
34+
hash_value = ((hash_value << 5) + hash_value) + ord(x)
35+
return hash_value & 0xFFFFFFFF

‎hashes/sdbm.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def sdbm(plain_text: str) -> int:
3131
>>> sdbm('scramble bits')
3232
730247649148944819640658295400555317318720608290373040936089
3333
"""
34-
hash = 0
34+
hash_value = 0
3535
for plain_chr in plain_text:
36-
hash = ord(plain_chr) + (hash << 6) + (hash << 16) - hash
37-
return hash
36+
hash_value = (
37+
ord(plain_chr) + (hash_value << 6) + (hash_value << 16) - hash_value
38+
)
39+
return hash_value

‎maths/armstrong_numbers.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def armstrong_number(n: int) -> bool:
2525
return False
2626

2727
# Initialization of sum and number of digits.
28-
sum = 0
28+
total = 0
2929
number_of_digits = 0
3030
temp = n
3131
# Calculation of digits of the number
@@ -36,9 +36,9 @@ def armstrong_number(n: int) -> bool:
3636
temp = n
3737
while temp > 0:
3838
rem = temp % 10
39-
sum += rem**number_of_digits
39+
total += rem**number_of_digits
4040
temp //= 10
41-
return n == sum
41+
return n == total
4242

4343

4444
def pluperfect_number(n: int) -> bool:
@@ -55,17 +55,17 @@ def pluperfect_number(n: int) -> bool:
5555
# Init a "histogram" of the digits
5656
digit_histogram = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
5757
digit_total = 0
58-
sum = 0
58+
total = 0
5959
temp = n
6060
while temp > 0:
6161
temp, rem = divmod(temp, 10)
6262
digit_histogram[rem] += 1
6363
digit_total += 1
6464

6565
for (cnt, i) in zip(digit_histogram, range(len(digit_histogram))):
66-
sum += cnt * i**digit_total
66+
total += cnt * i**digit_total
6767

68-
return n == sum
68+
return n == total
6969

7070

7171
def narcissistic_number(n: int) -> bool:

‎maths/bailey_borwein_plouffe.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _subsum(
6767
@param precision: same as precision in main function
6868
@return: floating-point number whose integer part is not important
6969
"""
70-
sum = 0.0
70+
total = 0.0
7171
for sum_index in range(digit_pos_to_extract + precision):
7272
denominator = 8 * sum_index + denominator_addend
7373
if sum_index < digit_pos_to_extract:
@@ -79,8 +79,8 @@ def _subsum(
7979
)
8080
else:
8181
exponential_term = pow(16, digit_pos_to_extract - 1 - sum_index)
82-
sum += exponential_term / denominator
83-
return sum
82+
total += exponential_term / denominator
83+
return total
8484

8585

8686
if __name__ == "__main__":

‎maths/kadanes.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ def negative_exist(arr: list) -> int:
1414
[-2, 0, 0, 0, 0]
1515
"""
1616
arr = arr or [0]
17-
max = arr[0]
17+
max_number = arr[0]
1818
for i in arr:
1919
if i >= 0:
2020
return 0
21-
elif max <= i:
22-
max = i
23-
return max
21+
elif max_number <= i:
22+
max_number = i
23+
return max_number
2424

2525

2626
def kadanes(arr: list) -> int:

‎maths/prime_numbers.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from collections.abc import Generator
33

44

5-
def slow_primes(max: int) -> Generator[int, None, None]:
5+
def slow_primes(max_n: int) -> Generator[int, None, None]:
66
"""
77
Return a list of all primes numbers up to max.
88
>>> list(slow_primes(0))
@@ -20,7 +20,7 @@ def slow_primes(max: int) -> Generator[int, None, None]:
2020
>>> list(slow_primes(10000))[-1]
2121
9973
2222
"""
23-
numbers: Generator = (i for i in range(1, (max + 1)))
23+
numbers: Generator = (i for i in range(1, (max_n + 1)))
2424
for i in (n for n in numbers if n > 1):
2525
for j in range(2, i):
2626
if (i % j) == 0:
@@ -29,7 +29,7 @@ def slow_primes(max: int) -> Generator[int, None, None]:
2929
yield i
3030

3131

32-
def primes(max: int) -> Generator[int, None, None]:
32+
def primes(max_n: int) -> Generator[int, None, None]:
3333
"""
3434
Return a list of all primes numbers up to max.
3535
>>> list(primes(0))
@@ -47,7 +47,7 @@ def primes(max: int) -> Generator[int, None, None]:
4747
>>> list(primes(10000))[-1]
4848
9973
4949
"""
50-
numbers: Generator = (i for i in range(1, (max + 1)))
50+
numbers: Generator = (i for i in range(1, (max_n + 1)))
5151
for i in (n for n in numbers if n > 1):
5252
# only need to check for factors up to sqrt(i)
5353
bound = int(math.sqrt(i)) + 1
@@ -58,7 +58,7 @@ def primes(max: int) -> Generator[int, None, None]:
5858
yield i
5959

6060

61-
def fast_primes(max: int) -> Generator[int, None, None]:
61+
def fast_primes(max_n: int) -> Generator[int, None, None]:
6262
"""
6363
Return a list of all primes numbers up to max.
6464
>>> list(fast_primes(0))
@@ -76,9 +76,9 @@ def fast_primes(max: int) -> Generator[int, None, None]:
7676
>>> list(fast_primes(10000))[-1]
7777
9973
7878
"""
79-
numbers: Generator = (i for i in range(1, (max + 1), 2))
79+
numbers: Generator = (i for i in range(1, (max_n + 1), 2))
8080
# It's useless to test even numbers as they will not be prime
81-
if max > 2:
81+
if max_n > 2:
8282
yield 2 # Because 2 will not be tested, it's necessary to yield it now
8383
for i in (n for n in numbers if n > 1):
8484
bound = int(math.sqrt(i)) + 1

‎maths/sum_of_arithmetic_series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ def sum_of_series(first_term: int, common_diff: int, num_of_terms: int) -> float
88
>>> sum_of_series(1, 10, 100)
99
49600.0
1010
"""
11-
sum = (num_of_terms / 2) * (2 * first_term + (num_of_terms - 1) * common_diff)
11+
total = (num_of_terms / 2) * (2 * first_term + (num_of_terms - 1) * common_diff)
1212
# formula for sum of series
13-
return sum
13+
return total
1414

1515

1616
def main():

‎neural_network/2_hidden_layers_neural_network.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def train(self, output: numpy.ndarray, iterations: int, give_loss: bool) -> None
182182
loss = numpy.mean(numpy.square(output - self.feedforward()))
183183
print(f"Iteration {iteration} Loss: {loss}")
184184

185-
def predict(self, input: numpy.ndarray) -> int:
185+
def predict(self, input_arr: numpy.ndarray) -> int:
186186
"""
187187
Predict's the output for the given input values using
188188
the trained neural network.
@@ -201,7 +201,7 @@ def predict(self, input: numpy.ndarray) -> int:
201201
"""
202202

203203
# Input values for which the predictions are to be made.
204-
self.array = input
204+
self.array = input_arr
205205

206206
self.layer_between_input_and_first_hidden_layer = sigmoid(
207207
numpy.dot(self.array, self.input_layer_and_first_hidden_layer_weights)
@@ -264,7 +264,7 @@ def example() -> int:
264264
True
265265
"""
266266
# Input values.
267-
input = numpy.array(
267+
test_input = numpy.array(
268268
(
269269
[0, 0, 0],
270270
[0, 0, 1],
@@ -282,7 +282,9 @@ def example() -> int:
282282
output = numpy.array(([0], [1], [1], [0], [1], [0], [0], [1]), dtype=numpy.float64)
283283

284284
# Calling neural network class.
285-
neural_network = TwoHiddenLayerNeuralNetwork(input_array=input, output_array=output)
285+
neural_network = TwoHiddenLayerNeuralNetwork(
286+
input_array=test_input, output_array=output
287+
)
286288

287289
# Calling training function.
288290
# Set give_loss to True if you want to see loss in every iteration.

‎neural_network/convolution_neural_network.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -140,24 +140,24 @@ def convolute(self, data, convs, w_convs, thre_convs, conv_step):
140140
focus_list = np.asarray(focus1_list)
141141
return focus_list, data_featuremap
142142

143-
def pooling(self, featuremaps, size_pooling, type="average_pool"):
143+
def pooling(self, featuremaps, size_pooling, pooling_type="average_pool"):
144144
# pooling process
145145
size_map = len(featuremaps[0])
146146
size_pooled = int(size_map / size_pooling)
147147
featuremap_pooled = []
148148
for i_map in range(len(featuremaps)):
149-
map = featuremaps[i_map]
149+
feature_map = featuremaps[i_map]
150150
map_pooled = []
151151
for i_focus in range(0, size_map, size_pooling):
152152
for j_focus in range(0, size_map, size_pooling):
153-
focus = map[
153+
focus = feature_map[
154154
i_focus : i_focus + size_pooling,
155155
j_focus : j_focus + size_pooling,
156156
]
157-
if type == "average_pool":
157+
if pooling_type == "average_pool":
158158
# average pooling
159159
map_pooled.append(np.average(focus))
160-
elif type == "max_pooling":
160+
elif pooling_type == "max_pooling":
161161
# max pooling
162162
map_pooled.append(np.max(focus))
163163
map_pooled = np.asmatrix(map_pooled).reshape(size_pooled, size_pooled)

‎neural_network/perceptron.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def sign(self, u: float) -> int:
182182
[0.2012, 0.2611, 5.4631],
183183
]
184184

185-
exit = [
185+
target = [
186186
-1,
187187
-1,
188188
-1,
@@ -222,7 +222,7 @@ def sign(self, u: float) -> int:
222222
doctest.testmod()
223223

224224
network = Perceptron(
225-
sample=samples, target=exit, learning_rate=0.01, epoch_number=1000, bias=-1
225+
sample=samples, target=target, learning_rate=0.01, epoch_number=1000, bias=-1
226226
)
227227
network.training()
228228
print("Finished training perceptron")

‎project_euler/problem_065/sol1.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def sum_digits(num: int) -> int:
7171
return digit_sum
7272

7373

74-
def solution(max: int = 100) -> int:
74+
def solution(max_n: int = 100) -> int:
7575
"""
7676
Returns the sum of the digits in the numerator of the max-th convergent of
7777
the continued fraction for e.
@@ -86,7 +86,7 @@ def solution(max: int = 100) -> int:
8686
pre_numerator = 1
8787
cur_numerator = 2
8888

89-
for i in range(2, max + 1):
89+
for i in range(2, max_n + 1):
9090
temp = pre_numerator
9191
e_cont = 2 * i // 3 if i % 3 == 0 else 1
9292
pre_numerator = cur_numerator

‎project_euler/problem_070/sol1.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def has_same_digits(num1: int, num2: int) -> bool:
7272
return sorted(str(num1)) == sorted(str(num2))
7373

7474

75-
def solution(max: int = 10000000) -> int:
75+
def solution(max_n: int = 10000000) -> int:
7676
"""
7777
Finds the value of n from 1 to max such that n/φ(n) produces a minimum.
7878
@@ -85,9 +85,9 @@ def solution(max: int = 10000000) -> int:
8585

8686
min_numerator = 1 # i
8787
min_denominator = 0 # φ(i)
88-
totients = get_totients(max + 1)
88+
totients = get_totients(max_n + 1)
8989

90-
for i in range(2, max + 1):
90+
for i in range(2, max_n + 1):
9191
t = totients[i]
9292

9393
if i * min_denominator < min_numerator * t and has_same_digits(i, t):

‎sorts/odd_even_sort.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ def odd_even_sort(input_list: list) -> list:
2020
>>> odd_even_sort([1 ,2 ,3 ,4])
2121
[1, 2, 3, 4]
2222
"""
23-
sorted = False
24-
while sorted is False: # Until all the indices are traversed keep looping
25-
sorted = True
23+
is_sorted = False
24+
while is_sorted is False: # Until all the indices are traversed keep looping
25+
is_sorted = True
2626
for i in range(0, len(input_list) - 1, 2): # iterating over all even indices
2727
if input_list[i] > input_list[i + 1]:
2828

2929
input_list[i], input_list[i + 1] = input_list[i + 1], input_list[i]
3030
# swapping if elements not in order
31-
sorted = False
31+
is_sorted = False
3232

3333
for i in range(1, len(input_list) - 1, 2): # iterating over all odd indices
3434
if input_list[i] > input_list[i + 1]:
3535
input_list[i], input_list[i + 1] = input_list[i + 1], input_list[i]
3636
# swapping if elements not in order
37-
sorted = False
37+
is_sorted = False
3838
return input_list
3939

4040

‎strings/snake_case_to_camel_pascal_case.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def snake_to_camel_case(input: str, use_pascal: bool = False) -> str:
1+
def snake_to_camel_case(input_str: str, use_pascal: bool = False) -> str:
22
"""
33
Transforms a snake_case given string to camelCase (or PascalCase if indicated)
44
(defaults to not use Pascal)
@@ -26,14 +26,14 @@ def snake_to_camel_case(input: str, use_pascal: bool = False) -> str:
2626
ValueError: Expected boolean as use_pascal parameter, found <class 'str'>
2727
"""
2828

29-
if not isinstance(input, str):
30-
raise ValueError(f"Expected string as input, found {type(input)}")
29+
if not isinstance(input_str, str):
30+
raise ValueError(f"Expected string as input, found {type(input_str)}")
3131
if not isinstance(use_pascal, bool):
3232
raise ValueError(
3333
f"Expected boolean as use_pascal parameter, found {type(use_pascal)}"
3434
)
3535

36-
words = input.split("_")
36+
words = input_str.split("_")
3737

3838
start_index = 0 if use_pascal else 1
3939

0 commit comments

Comments
 (0)
Please sign in to comment.