Skip to content

Commit 7f04e5c

Browse files
matkosoricpoyea
andauthored
contribution guidelines checks (TheAlgorithms#1787)
* spelling corrections * review * improved documentation, removed redundant variables, added testing * added type hint * camel case to snake case * spelling fix * review * python --> Python # it is a brand name, not a snake * explicit cast to int * spaces in int list * "!= None" to "is not None" * Update comb_sort.py * various spelling corrections in documentation & several variables naming conventions fix * + char in file name * import dependency - bug fix Co-authored-by: John Law <[email protected]>
1 parent 2b19e84 commit 7f04e5c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+198
-198
lines changed

Diff for: .gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ wheels/
2626
MANIFEST
2727

2828
# PyInstaller
29-
# Usually these files are written by a python script from a template
29+
# Usually these files are written by a Python script from a template
3030
# before PyInstaller builds the exe, so as to inject date/other infos into it.
3131
*.manifest
3232
*.spec

Diff for: DIRECTORY.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@
263263
* [Support Vector Machines](https://github.com/TheAlgorithms/Python/blob/master/machine_learning/support_vector_machines.py)
264264

265265
## Maths
266-
* [3N+1](https://github.com/TheAlgorithms/Python/blob/master/maths/3n+1.py)
266+
* [3N+1](https://github.com/TheAlgorithms/Python/blob/master/maths/3n_plus_1.py)
267267
* [Abs](https://github.com/TheAlgorithms/Python/blob/master/maths/abs.py)
268268
* [Abs Max](https://github.com/TheAlgorithms/Python/blob/master/maths/abs_max.py)
269269
* [Abs Min](https://github.com/TheAlgorithms/Python/blob/master/maths/abs_min.py)

Diff for: backtracking/n_queens.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def solve(board, row):
4242
"""
4343
It creates a state space tree and calls the safe function until it receives a
4444
False Boolean and terminates that branch and backtracks to the next
45-
poosible solution branch.
45+
possible solution branch.
4646
"""
4747
if row >= len(board):
4848
"""
@@ -56,7 +56,7 @@ def solve(board, row):
5656
return
5757
for i in range(len(board)):
5858
"""
59-
For every row it iterates through each column to check if it is feesible to place a
59+
For every row it iterates through each column to check if it is feasible to place a
6060
queen there.
6161
If all the combinations for that particular branch are successful the board is
6262
reinitialized for the next possible combination.

Diff for: ciphers/hill_cipher.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ def __init__(self, encrypt_key):
6565
encrypt_key is an NxN numpy matrix
6666
"""
6767
self.encrypt_key = self.modulus(encrypt_key) # mod36 calc's on the encrypt key
68-
self.checkDeterminant() # validate the determinant of the encryption key
68+
self.check_determinant() # validate the determinant of the encryption key
6969
self.decrypt_key = None
7070
self.break_key = encrypt_key.shape[0]
7171

72-
def checkDeterminant(self):
72+
def check_determinant(self):
7373
det = round(numpy.linalg.det(self.encrypt_key))
7474

7575
if det < 0:
@@ -83,7 +83,7 @@ def checkDeterminant(self):
8383
)
8484
)
8585

86-
def processText(self, text):
86+
def process_text(self, text):
8787
text = list(text.upper())
8888
text = [char for char in text if char in self.key_string]
8989

@@ -94,7 +94,7 @@ def processText(self, text):
9494
return "".join(text)
9595

9696
def encrypt(self, text):
97-
text = self.processText(text.upper())
97+
text = self.process_text(text.upper())
9898
encrypted = ""
9999

100100
for i in range(0, len(text) - self.break_key + 1, self.break_key):
@@ -109,7 +109,7 @@ def encrypt(self, text):
109109

110110
return encrypted
111111

112-
def makeDecryptKey(self):
112+
def make_decrypt_key(self):
113113
det = round(numpy.linalg.det(self.encrypt_key))
114114

115115
if det < 0:
@@ -129,8 +129,8 @@ def makeDecryptKey(self):
129129
return self.toInt(self.modulus(inv_key))
130130

131131
def decrypt(self, text):
132-
self.decrypt_key = self.makeDecryptKey()
133-
text = self.processText(text.upper())
132+
self.decrypt_key = self.make_decrypt_key()
133+
text = self.process_text(text.upper())
134134
decrypted = ""
135135

136136
for i in range(0, len(text) - self.break_key + 1, self.break_key):

Diff for: ciphers/onepad_cipher.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class Onepad:
55
def encrypt(self, text):
6-
"""Function to encrypt text using psedo-random numbers"""
6+
"""Function to encrypt text using pseudo-random numbers"""
77
plain = [ord(i) for i in text]
88
key = []
99
cipher = []
@@ -15,7 +15,7 @@ def encrypt(self, text):
1515
return cipher, key
1616

1717
def decrypt(self, cipher, key):
18-
"""Function to decrypt text using psedo-random numbers."""
18+
"""Function to decrypt text using pseudo-random numbers."""
1919
plain = []
2020
for i in range(len(key)):
2121
p = int((cipher[i] - (key[i]) ** 2) / key[i])

Diff for: data_structures/binary_tree/binary_search_tree.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ def __str__(self):
2828
"""
2929
return str(self.root)
3030

31-
def __reassign_nodes(self, node, newChildren):
32-
if newChildren is not None: # reset its kids
33-
newChildren.parent = node.parent
31+
def __reassign_nodes(self, node, new_children):
32+
if new_children is not None: # reset its kids
33+
new_children.parent = node.parent
3434
if node.parent is not None: # reset its parent
3535
if self.is_right(node): # If it is the right children
36-
node.parent.right = newChildren
36+
node.parent.right = new_children
3737
else:
38-
node.parent.left = newChildren
38+
node.parent.left = new_children
3939
else:
40-
self.root = newChildren
40+
self.root = new_children
4141

4242
def is_right(self, node):
4343
return node == node.parent.right
@@ -117,39 +117,39 @@ def remove(self, value):
117117
elif node.right is None: # Has only left children
118118
self.__reassign_nodes(node, node.left)
119119
else:
120-
tmpNode = self.get_max(
120+
tmp_node = self.get_max(
121121
node.left
122-
) # Gets the max value of the left branch
123-
self.remove(tmpNode.value)
122+
) # Gets the max value of the left branch
123+
self.remove(tmp_node.value)
124124
node.value = (
125-
tmpNode.value
126-
) # Assigns the value to the node to delete and keesp tree structure
125+
tmp_node.value
126+
) # Assigns the value to the node to delete and keep tree structure
127127

128128
def preorder_traverse(self, node):
129129
if node is not None:
130-
yield node # Preorder Traversal
130+
yield node # Preorder Traversal
131131
yield from self.preorder_traverse(node.left)
132132
yield from self.preorder_traverse(node.right)
133133

134-
def traversal_tree(self, traversalFunction=None):
134+
def traversal_tree(self, traversal_function=None):
135135
"""
136136
This function traversal the tree.
137137
You can pass a function to traversal the tree as needed by client code
138138
"""
139-
if traversalFunction is None:
139+
if traversal_function is None:
140140
return self.preorder_traverse(self.root)
141141
else:
142-
return traversalFunction(self.root)
142+
return traversal_function(self.root)
143143

144144

145145
def postorder(curr_node):
146146
"""
147147
postOrder (left, right, self)
148148
"""
149-
nodeList = list()
149+
node_list = list()
150150
if curr_node is not None:
151-
nodeList = postorder(curr_node.left) + postorder(curr_node.right) + [curr_node]
152-
return nodeList
151+
node_list = postorder(curr_node.left) + postorder(curr_node.right) + [curr_node]
152+
return node_list
153153

154154

155155
def binary_search_tree():

Diff for: data_structures/binary_tree/number_of_possible_binary_trees.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def binary_tree_count(node_count: int) -> int:
8282
"""
8383
Return the number of possible of binary trees.
8484
:param n: number of nodes
85-
:return: Number of possilble binary trees
85+
:return: Number of possible binary trees
8686
8787
>>> binary_tree_count(5)
8888
5040

Diff for: data_structures/linked_list/deque_doubly.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, link_p, element, link_n):
2121

2222
def has_next_and_prev(self):
2323
return " Prev -> {0}, Next -> {1}".format(
24-
self._prev != None, self._next != None
24+
self._prev is not None, self._next is not None
2525
)
2626

2727
def __init__(self):

Diff for: data_structures/linked_list/doubly_linked_list.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def isEmpty(self): # Will return True if the list is empty
6262

6363
def display(self): # Prints contents of the list
6464
current = self.head
65-
while current != None:
65+
while current is not None:
6666
current.displayLink()
6767
current = current.next
6868
print()

Diff for: data_structures/queue/queue_on_list.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Queue represented by a python list"""
1+
"""Queue represented by a Python list"""
22

33

44
class Queue:

Diff for: digital_image_processing/change_contrast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Changing contrast with PIL
33
44
This algorithm is used in
5-
https://noivce.pythonanywhere.com/ python web app.
5+
https://noivce.pythonanywhere.com/ Python web app.
66
77
python/black: True
88
flake8 : True

Diff for: divide_and_conquer/convex_hull.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -344,19 +344,19 @@ def convex_hull_recursive(points):
344344
right_most_point = points[n - 1]
345345

346346
convex_set = {left_most_point, right_most_point}
347-
upperhull = []
348-
lowerhull = []
347+
upper_hull = []
348+
lower_hull = []
349349

350350
for i in range(1, n - 1):
351351
det = _det(left_most_point, right_most_point, points[i])
352352

353353
if det > 0:
354-
upperhull.append(points[i])
354+
upper_hull.append(points[i])
355355
elif det < 0:
356-
lowerhull.append(points[i])
356+
lower_hull.append(points[i])
357357

358-
_construct_hull(upperhull, left_most_point, right_most_point, convex_set)
359-
_construct_hull(lowerhull, right_most_point, left_most_point, convex_set)
358+
_construct_hull(upper_hull, left_most_point, right_most_point, convex_set)
359+
_construct_hull(lower_hull, right_most_point, left_most_point, convex_set)
360360

361361
return sorted(convex_set)
362362

Diff for: dynamic_programming/bitmask.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
3-
This is a python implementation for questions involving task assignments between people.
3+
This is a Python implementation for questions involving task assignments between people.
44
Here Bitmasking and DP are used for solving this.
55
66
Question :-
@@ -25,41 +25,41 @@ def __init__(self, task_performed, total):
2525

2626
self.task = defaultdict(list) # stores the list of persons for each task
2727

28-
# finalmask is used to check if all persons are included by setting all bits to 1
29-
self.finalmask = (1 << len(task_performed)) - 1
28+
# final_mask is used to check if all persons are included by setting all bits to 1
29+
self.final_mask = (1 << len(task_performed)) - 1
3030

31-
def CountWaysUtil(self, mask, taskno):
31+
def CountWaysUtil(self, mask, task_no):
3232

3333
# if mask == self.finalmask all persons are distributed tasks, return 1
34-
if mask == self.finalmask:
34+
if mask == self.final_mask:
3535
return 1
3636

3737
# if not everyone gets the task and no more tasks are available, return 0
38-
if taskno > self.total_tasks:
38+
if task_no > self.total_tasks:
3939
return 0
4040

4141
# if case already considered
42-
if self.dp[mask][taskno] != -1:
43-
return self.dp[mask][taskno]
42+
if self.dp[mask][task_no] != -1:
43+
return self.dp[mask][task_no]
4444

4545
# Number of ways when we don't this task in the arrangement
46-
total_ways_util = self.CountWaysUtil(mask, taskno + 1)
46+
total_ways_util = self.CountWaysUtil(mask, task_no + 1)
4747

4848
# now assign the tasks one by one to all possible persons and recursively assign for the remaining tasks.
49-
if taskno in self.task:
50-
for p in self.task[taskno]:
49+
if task_no in self.task:
50+
for p in self.task[task_no]:
5151

5252
# if p is already given a task
5353
if mask & (1 << p):
5454
continue
5555

5656
# assign this task to p and change the mask value. And recursively assign tasks with the new mask value.
57-
total_ways_util += self.CountWaysUtil(mask | (1 << p), taskno + 1)
57+
total_ways_util += self.CountWaysUtil(mask | (1 << p), task_no + 1)
5858

5959
# save the value.
60-
self.dp[mask][taskno] = total_ways_util
60+
self.dp[mask][task_no] = total_ways_util
6161

62-
return self.dp[mask][taskno]
62+
return self.dp[mask][task_no]
6363

6464
def countNoOfWays(self, task_performed):
6565

Diff for: dynamic_programming/fibonacci.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def get(self, sequence_no=None):
2828
[0, 1, 1, 2, 3, 5]
2929
[]
3030
"""
31-
if sequence_no != None:
31+
if sequence_no is not None:
3232
if sequence_no < len(self.fib_array):
3333
return print(self.fib_array[: sequence_no + 1])
3434
else:

Diff for: fuzzy_logic/fuzzy_operations.py

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

1212

1313
if __name__ == "__main__":
14-
# Create universe of discourse in python using linspace ()
14+
# Create universe of discourse in Python using linspace ()
1515
X = np.linspace(start=0, stop=75, num=75, endpoint=True, retstep=False)
1616

1717
# Create two fuzzy sets by defining any membership function (trapmf(), gbellmf(),gaussmf(), etc).

Diff for: graphs/bellman_ford.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def printDist(dist, V):
88

99

1010
def BellmanFord(graph: List[Dict[str, int]], V: int, E: int, src: int) -> int:
11-
r"""
11+
"""
1212
Returns shortest paths from a vertex src to all
1313
other vertices.
1414
"""

Diff for: graphs/directed_and_undirected_(weighted)_graph.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import math as math
44
import time
55

6-
# the dfault weight is 1 if not assigned but all the implementation is weighted
6+
# the default weight is 1 if not assigned but all the implementation is weighted
77

88

99
class DirectedGraph:

0 commit comments

Comments
 (0)