mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Fixes unused variable errors in LGTM (#1746)
* Fixes unsed variable errors in LGTM * Fixes integer check * Fixes failing tests
This commit is contained in:
parent
fde31c93a3
commit
7b7c1a0135
|
@ -29,9 +29,6 @@ def mixed_keyword(key="college", pt="UNIVERSITY"):
|
||||||
# print(temp)
|
# print(temp)
|
||||||
alpha = []
|
alpha = []
|
||||||
modalpha = []
|
modalpha = []
|
||||||
# modalpha.append(temp)
|
|
||||||
dic = dict()
|
|
||||||
c = 0
|
|
||||||
for i in range(65, 91):
|
for i in range(65, 91):
|
||||||
t = chr(i)
|
t = chr(i)
|
||||||
alpha.append(t)
|
alpha.append(t)
|
||||||
|
|
|
@ -76,7 +76,7 @@ class BinarySearchTree:
|
||||||
|
|
||||||
def search(self, value):
|
def search(self, value):
|
||||||
if self.empty():
|
if self.empty():
|
||||||
raise IndexError("Warning: Tree is empty! please use another. ")
|
raise IndexError("Warning: Tree is empty! please use another.")
|
||||||
else:
|
else:
|
||||||
node = self.root
|
node = self.root
|
||||||
# use lazy evaluation here to avoid NoneType Attribute error
|
# use lazy evaluation here to avoid NoneType Attribute error
|
||||||
|
@ -112,7 +112,6 @@ class BinarySearchTree:
|
||||||
if node is not None:
|
if node is not None:
|
||||||
if node.left is None and node.right is None: # If it has no children
|
if node.left is None and node.right is None: # If it has no children
|
||||||
self.__reassign_nodes(node, None)
|
self.__reassign_nodes(node, None)
|
||||||
node = None
|
|
||||||
elif node.left is None: # Has only right children
|
elif node.left is None: # Has only right children
|
||||||
self.__reassign_nodes(node, node.right)
|
self.__reassign_nodes(node, node.right)
|
||||||
elif node.right is None: # Has only left children
|
elif node.right is None: # Has only left children
|
||||||
|
@ -154,7 +153,7 @@ def postorder(curr_node):
|
||||||
|
|
||||||
|
|
||||||
def binary_search_tree():
|
def binary_search_tree():
|
||||||
r"""
|
"""
|
||||||
Example
|
Example
|
||||||
8
|
8
|
||||||
/ \
|
/ \
|
||||||
|
@ -164,15 +163,15 @@ def binary_search_tree():
|
||||||
/ \ /
|
/ \ /
|
||||||
4 7 13
|
4 7 13
|
||||||
|
|
||||||
>>> t = BinarySearchTree().insert(8, 3, 6, 1, 10, 14, 13, 4, 7)
|
>>> t = BinarySearchTree().insert(8, 3, 6, 1, 10, 14, 13, 4, 7)
|
||||||
>>> print(" ".join(repr(i.value) for i in t.traversal_tree()))
|
>>> print(" ".join(repr(i.value) for i in t.traversal_tree()))
|
||||||
8 3 1 6 4 7 10 14 13
|
8 3 1 6 4 7 10 14 13
|
||||||
>>> print(" ".join(repr(i.value) for i in t.traversal_tree(postorder)))
|
>>> print(" ".join(repr(i.value) for i in t.traversal_tree(postorder)))
|
||||||
1 4 7 6 3 13 14 10 8
|
1 4 7 6 3 13 14 10 8
|
||||||
>>> BinarySearchTree().search(6)
|
>>> BinarySearchTree().search(6)
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
...
|
...
|
||||||
IndexError: Warning: Tree is empty! please use another.
|
IndexError: Warning: Tree is empty! please use another.
|
||||||
"""
|
"""
|
||||||
testlist = (8, 3, 6, 1, 10, 14, 13, 4, 7)
|
testlist = (8, 3, 6, 1, 10, 14, 13, 4, 7)
|
||||||
t = BinarySearchTree()
|
t = BinarySearchTree()
|
||||||
|
@ -201,10 +200,8 @@ def binary_search_tree():
|
||||||
print(t)
|
print(t)
|
||||||
|
|
||||||
|
|
||||||
二叉搜索树 = binary_search_tree
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import doctest
|
import doctest
|
||||||
|
|
||||||
doctest.testmod()
|
doctest.testmod()
|
||||||
binary_search_tree()
|
# binary_search_tree()
|
||||||
|
|
|
@ -52,7 +52,6 @@ def search(grid, init, goal, cost, heuristic):
|
||||||
|
|
||||||
while not found and not resign:
|
while not found and not resign:
|
||||||
if len(cell) == 0:
|
if len(cell) == 0:
|
||||||
resign = True
|
|
||||||
return "FAIL"
|
return "FAIL"
|
||||||
else:
|
else:
|
||||||
cell.sort() # to choose the least costliest action so as to move closer to the goal
|
cell.sort() # to choose the least costliest action so as to move closer to the goal
|
||||||
|
@ -61,7 +60,6 @@ def search(grid, init, goal, cost, heuristic):
|
||||||
x = next[2]
|
x = next[2]
|
||||||
y = next[3]
|
y = next[3]
|
||||||
g = next[1]
|
g = next[1]
|
||||||
f = next[0]
|
|
||||||
|
|
||||||
if x == goal[0] and y == goal[1]:
|
if x == goal[0] and y == goal[1]:
|
||||||
found = True
|
found = True
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
* This code implement the Hamming code:
|
* This code implement the Hamming code:
|
||||||
https://en.wikipedia.org/wiki/Hamming_code - In telecommunication,
|
https://en.wikipedia.org/wiki/Hamming_code - In telecommunication,
|
||||||
Hamming codes are a family of linear error-correcting codes. Hamming
|
Hamming codes are a family of linear error-correcting codes. Hamming
|
||||||
codes can detect up to two-bit errors or correct one-bit errors
|
codes can detect up to two-bit errors or correct one-bit errors
|
||||||
without detection of uncorrected errors. By contrast, the simple
|
without detection of uncorrected errors. By contrast, the simple
|
||||||
parity code cannot correct errors, and can detect only an odd number
|
parity code cannot correct errors, and can detect only an odd number
|
||||||
of bits in error. Hamming codes are perfect codes, that is, they
|
of bits in error. Hamming codes are perfect codes, that is, they
|
||||||
achieve the highest possible rate for codes with their block length
|
achieve the highest possible rate for codes with their block length
|
||||||
and minimum distance of three.
|
and minimum distance of three.
|
||||||
|
|
||||||
* the implemented code consists of:
|
* the implemented code consists of:
|
||||||
|
@ -19,15 +19,15 @@
|
||||||
* return the encoded message
|
* return the encoded message
|
||||||
* a function responsible for decoding the message (receptorConverter)
|
* a function responsible for decoding the message (receptorConverter)
|
||||||
* return the decoded message and a ack of data integrity
|
* return the decoded message and a ack of data integrity
|
||||||
|
|
||||||
* how to use:
|
* how to use:
|
||||||
to be used you must declare how many parity bits (sizePari)
|
to be used you must declare how many parity bits (sizePari)
|
||||||
you want to include in the message.
|
you want to include in the message.
|
||||||
it is desired (for test purposes) to select a bit to be set
|
it is desired (for test purposes) to select a bit to be set
|
||||||
as an error. This serves to check whether the code is working correctly.
|
as an error. This serves to check whether the code is working correctly.
|
||||||
Lastly, the variable of the message/word that must be desired to be
|
Lastly, the variable of the message/word that must be desired to be
|
||||||
encoded (text).
|
encoded (text).
|
||||||
|
|
||||||
* how this work:
|
* how this work:
|
||||||
declaration of variables (sizePari, be, text)
|
declaration of variables (sizePari, be, text)
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ def emitterConverter(sizePar, data):
|
||||||
"""
|
"""
|
||||||
:param sizePar: how many parity bits the message must have
|
:param sizePar: how many parity bits the message must have
|
||||||
:param data: information bits
|
:param data: information bits
|
||||||
:return: message to be transmitted by unreliable medium
|
:return: message to be transmitted by unreliable medium
|
||||||
- bits of information merged with parity bits
|
- bits of information merged with parity bits
|
||||||
|
|
||||||
>>> emitterConverter(4, "101010111111")
|
>>> emitterConverter(4, "101010111111")
|
||||||
|
@ -84,7 +84,6 @@ def emitterConverter(sizePar, data):
|
||||||
dataOut = []
|
dataOut = []
|
||||||
parity = []
|
parity = []
|
||||||
binPos = [bin(x)[2:] for x in range(1, sizePar + len(data) + 1)]
|
binPos = [bin(x)[2:] for x in range(1, sizePar + len(data) + 1)]
|
||||||
pos = [x for x in range(1, sizePar + len(data) + 1)]
|
|
||||||
|
|
||||||
# sorted information data for the size of the output data
|
# sorted information data for the size of the output data
|
||||||
dataOrd = []
|
dataOrd = []
|
||||||
|
@ -188,7 +187,6 @@ def receptorConverter(sizePar, data):
|
||||||
dataOut = []
|
dataOut = []
|
||||||
parity = []
|
parity = []
|
||||||
binPos = [bin(x)[2:] for x in range(1, sizePar + len(dataOutput) + 1)]
|
binPos = [bin(x)[2:] for x in range(1, sizePar + len(dataOutput) + 1)]
|
||||||
pos = [x for x in range(1, sizePar + len(dataOutput) + 1)]
|
|
||||||
|
|
||||||
# sorted information data for the size of the output data
|
# sorted information data for the size of the output data
|
||||||
dataOrd = []
|
dataOrd = []
|
||||||
|
|
|
@ -68,7 +68,6 @@ def points_to_polynomial(coordinates):
|
||||||
# put the y values into a vector
|
# put the y values into a vector
|
||||||
vector = []
|
vector = []
|
||||||
while count_of_line < x:
|
while count_of_line < x:
|
||||||
count_in_line = 0
|
|
||||||
vector.append(coordinates[count_of_line][1])
|
vector.append(coordinates[count_of_line][1])
|
||||||
count_of_line += 1
|
count_of_line += 1
|
||||||
|
|
||||||
|
|
|
@ -111,12 +111,9 @@ def inverse(matrix):
|
||||||
|
|
||||||
|
|
||||||
def _check_not_integer(matrix):
|
def _check_not_integer(matrix):
|
||||||
try:
|
if not isinstance(matrix, int) and not isinstance(matrix[0], int):
|
||||||
rows = len(matrix)
|
|
||||||
cols = len(matrix[0])
|
|
||||||
return True
|
return True
|
||||||
except TypeError:
|
raise TypeError("Expected a matrix, got int/list instead")
|
||||||
raise TypeError("Cannot input an integer value, it must be a matrix")
|
|
||||||
|
|
||||||
|
|
||||||
def _shape(matrix):
|
def _shape(matrix):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user