Remove file-level flake8 suppression (#7844)

* Remove file-level flake8 suppression

* updating DIRECTORY.md

* Fix tests

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
Andrey 2022-10-29 23:45:21 +03:00 committed by GitHub
parent 47ddba1d91
commit 1550731cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 36 deletions

View File

@ -671,6 +671,7 @@
## Physics ## Physics
* [Casimir Effect](physics/casimir_effect.py) * [Casimir Effect](physics/casimir_effect.py)
* [Centripetal Force](physics/centripetal_force.py)
* [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py) * [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py)
* [Kinetic Energy](physics/kinetic_energy.py) * [Kinetic Energy](physics/kinetic_energy.py)
* [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py) * [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py)
@ -1069,6 +1070,7 @@
* [Is Palindrome](strings/is_palindrome.py) * [Is Palindrome](strings/is_palindrome.py)
* [Is Pangram](strings/is_pangram.py) * [Is Pangram](strings/is_pangram.py)
* [Is Spain National Id](strings/is_spain_national_id.py) * [Is Spain National Id](strings/is_spain_national_id.py)
* [Is Srilankan Phone Number](strings/is_srilankan_phone_number.py)
* [Jaro Winkler](strings/jaro_winkler.py) * [Jaro Winkler](strings/jaro_winkler.py)
* [Join](strings/join.py) * [Join](strings/join.py)
* [Knuth Morris Pratt](strings/knuth_morris_pratt.py) * [Knuth Morris Pratt](strings/knuth_morris_pratt.py)

View File

@ -1,5 +1,3 @@
# flake8: noqa
""" """
Binomial Heap Binomial Heap
Reference: Advanced Data Structures, Peter Brass Reference: Advanced Data Structures, Peter Brass
@ -22,7 +20,7 @@ class Node:
self.right = None self.right = None
self.parent = None self.parent = None
def mergeTrees(self, other): def merge_trees(self, other):
""" """
In-place merge of two binomial trees of equal size. In-place merge of two binomial trees of equal size.
Returns the root of the resulting tree Returns the root of the resulting tree
@ -75,9 +73,8 @@ class BinomialHeap:
30 30
Deleting - delete() test Deleting - delete() test
>>> for i in range(25): >>> [first_heap.delete_min() for _ in range(20)]
... print(first_heap.deleteMin(), end=" ") [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Create a new Heap Create a new Heap
>>> second_heap = BinomialHeap() >>> second_heap = BinomialHeap()
@ -97,8 +94,8 @@ class BinomialHeap:
# # # # # # # #
preOrder() test preOrder() test
>>> second_heap.preOrder() >>> " ".join(str(x) for x in second_heap.pre_order())
[(17, 0), ('#', 1), (31, 1), (20, 2), ('#', 3), ('#', 3), (34, 2), ('#', 3), ('#', 3)] "(17, 0) ('#', 1) (31, 1) (20, 2) ('#', 3) ('#', 3) (34, 2) ('#', 3) ('#', 3)"
printing Heap - __str__() test printing Heap - __str__() test
>>> print(second_heap) >>> print(second_heap)
@ -113,14 +110,17 @@ class BinomialHeap:
---# ---#
mergeHeaps() test mergeHeaps() test
>>> merged = second_heap.mergeHeaps(first_heap) >>>
>>> merged = second_heap.merge_heaps(first_heap)
>>> merged.peek() >>> merged.peek()
17 17
values in merged heap; (merge is inplace) values in merged heap; (merge is inplace)
>>> while not first_heap.isEmpty(): >>> results = []
... print(first_heap.deleteMin(), end=" ") >>> while not first_heap.is_empty():
17 20 25 26 27 28 29 31 34 ... results.append(first_heap.delete_min())
>>> results
[17, 20, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 34]
""" """
def __init__(self, bottom_root=None, min_node=None, heap_size=0): def __init__(self, bottom_root=None, min_node=None, heap_size=0):
@ -128,7 +128,7 @@ class BinomialHeap:
self.bottom_root = bottom_root self.bottom_root = bottom_root
self.min_node = min_node self.min_node = min_node
def mergeHeaps(self, other): def merge_heaps(self, other):
""" """
In-place merge of two binomial heaps. In-place merge of two binomial heaps.
Both of them become the resulting merged heap Both of them become the resulting merged heap
@ -180,7 +180,7 @@ class BinomialHeap:
next_node = i.parent.parent next_node = i.parent.parent
# Merging trees # Merging trees
i = i.mergeTrees(i.parent) i = i.merge_trees(i.parent)
# Updating links # Updating links
i.left = previous_node i.left = previous_node
@ -238,7 +238,7 @@ class BinomialHeap:
next_node = self.bottom_root.parent.parent next_node = self.bottom_root.parent.parent
# Merge # Merge
self.bottom_root = self.bottom_root.mergeTrees(self.bottom_root.parent) self.bottom_root = self.bottom_root.merge_trees(self.bottom_root.parent)
# Update Links # Update Links
self.bottom_root.parent = next_node self.bottom_root.parent = next_node
@ -252,10 +252,10 @@ class BinomialHeap:
""" """
return self.min_node.val return self.min_node.val
def isEmpty(self): def is_empty(self):
return self.size == 0 return self.size == 0
def deleteMin(self): def delete_min(self):
""" """
delete min element and return it delete min element and return it
""" """
@ -317,7 +317,7 @@ class BinomialHeap:
return min_value return min_value
# Remaining cases # Remaining cases
# Construct heap of right subtree # Construct heap of right subtree
newHeap = BinomialHeap( new_heap = BinomialHeap(
bottom_root=bottom_of_new, min_node=min_of_new, heap_size=size_of_new bottom_root=bottom_of_new, min_node=min_of_new, heap_size=size_of_new
) )
@ -354,11 +354,11 @@ class BinomialHeap:
self.min_node = i self.min_node = i
i = i.parent i = i.parent
# Merge heaps # Merge heaps
self.mergeHeaps(newHeap) self.merge_heaps(new_heap)
return min_value return min_value
def preOrder(self): def pre_order(self):
""" """
Returns the Pre-order representation of the heap including Returns the Pre-order representation of the heap including
values of nodes plus their level distance from the root; values of nodes plus their level distance from the root;
@ -369,9 +369,9 @@ class BinomialHeap:
while top_root.parent: while top_root.parent:
top_root = top_root.parent top_root = top_root.parent
# preorder # preorder
heap_preOrder = [] heap_pre_order = []
self.__traversal(top_root, heap_preOrder) self.__traversal(top_root, heap_pre_order)
return heap_preOrder return heap_pre_order
def __traversal(self, curr_node, preorder, level=0): def __traversal(self, curr_node, preorder, level=0):
""" """
@ -389,9 +389,9 @@ class BinomialHeap:
Overwriting str for a pre-order print of nodes in heap; Overwriting str for a pre-order print of nodes in heap;
Performance is poor, so use only for small examples Performance is poor, so use only for small examples
""" """
if self.isEmpty(): if self.is_empty():
return "" return ""
preorder_heap = self.preOrder() preorder_heap = self.pre_order()
return "\n".join(("-" * level + str(value)) for value, level in preorder_heap) return "\n".join(("-" * level + str(value)) for value, level in preorder_heap)

View File

@ -1,5 +1,3 @@
# flake8: noqa
"""The following implementation assumes that the activities """The following implementation assumes that the activities
are already sorted according to their finish time""" are already sorted according to their finish time"""
@ -10,11 +8,11 @@ single person, one at a time"""
# finish[] --> An array that contains finish time of all activities # finish[] --> An array that contains finish time of all activities
def printMaxActivities(start: list[int], finish: list[int]) -> None: def print_max_activities(start: list[int], finish: list[int]) -> None:
""" """
>>> start = [1, 3, 0, 5, 8, 5] >>> start = [1, 3, 0, 5, 8, 5]
>>> finish = [2, 4, 6, 7, 9, 9] >>> finish = [2, 4, 6, 7, 9, 9]
>>> printMaxActivities(start, finish) >>> print_max_activities(start, finish)
The following activities are selected: The following activities are selected:
0,1,3,4, 0,1,3,4,
""" """
@ -43,4 +41,4 @@ if __name__ == "__main__":
start = [1, 3, 0, 5, 8, 5] start = [1, 3, 0, 5, 8, 5]
finish = [2, 4, 6, 7, 9, 9] finish = [2, 4, 6, 7, 9, 9]
printMaxActivities(start, finish) print_max_activities(start, finish)

View File

@ -1,5 +1,3 @@
# flake8: noqa
""" """
This is pure Python implementation of tree traversal algorithms This is pure Python implementation of tree traversal algorithms
""" """
@ -157,16 +155,16 @@ def level_order_actual(node: TreeNode) -> None:
q: queue.Queue = queue.Queue() q: queue.Queue = queue.Queue()
q.put(node) q.put(node)
while not q.empty(): while not q.empty():
list = [] list_ = []
while not q.empty(): while not q.empty():
node_dequeued = q.get() node_dequeued = q.get()
print(node_dequeued.data, end=",") print(node_dequeued.data, end=",")
if node_dequeued.left: if node_dequeued.left:
list.append(node_dequeued.left) list_.append(node_dequeued.left)
if node_dequeued.right: if node_dequeued.right:
list.append(node_dequeued.right) list_.append(node_dequeued.right)
print() print()
for node in list: for node in list_:
q.put(node) q.put(node)