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

.gitignore

Lines changed: 1 addition & 1 deletion
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

DIRECTORY.md

Lines changed: 1 addition & 1 deletion
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)

backtracking/n_queens.py

Lines changed: 2 additions & 2 deletions
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.

ciphers/hill_cipher.py

Lines changed: 7 additions & 7 deletions
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):

ciphers/onepad_cipher.py

Lines changed: 2 additions & 2 deletions
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])

data_structures/binary_tree/binary_search_tree.py

Lines changed: 18 additions & 18 deletions
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():

data_structures/binary_tree/number_of_possible_binary_trees.py

Lines changed: 1 addition & 1 deletion
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

data_structures/linked_list/deque_doubly.py

Lines changed: 1 addition & 1 deletion
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):

data_structures/linked_list/doubly_linked_list.py

Lines changed: 1 addition & 1 deletion
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()

data_structures/queue/queue_on_list.py

Lines changed: 1 addition & 1 deletion
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:

0 commit comments

Comments
 (0)