From a868ac9b78b0258eeb312fafb32e99fd76c5d7b1 Mon Sep 17 00:00:00 2001 From: rfamilara Date: Sun, 27 Sep 2020 22:13:26 -0500 Subject: [PATCH 1/5] Completed names.py The tests were successful --- names/binary_search_tree.py | 31 +++++++ names/doubly_linked_list.py | 139 +++++++++++++++++++++++++++++++ names/names.py | 14 ++-- names/queue.py | 25 ++++++ names/stack.py | 34 ++++++++ names/test_binary_search_tree.py | 110 ++++++++++++++++++++++++ 6 files changed, 347 insertions(+), 6 deletions(-) create mode 100644 names/binary_search_tree.py create mode 100644 names/doubly_linked_list.py create mode 100644 names/queue.py create mode 100644 names/stack.py create mode 100644 names/test_binary_search_tree.py diff --git a/names/binary_search_tree.py b/names/binary_search_tree.py new file mode 100644 index 000000000..dc4c2c62e --- /dev/null +++ b/names/binary_search_tree.py @@ -0,0 +1,31 @@ +from queue import Queue +from stack import Stack + +class BSTNode: + def __init__(self, value): + self.value = value + self.left = None + self.right = None + + # Insert the given value into the tree + def insert(self, value): + if value < self.value: + if not self.left: + self.left = BSTNode(value) + else: + self.left.insert(value) + else: + if not self.right: + self.right = BSTNode(value) + else: + self.right.insert(value) + + # Return True if the tree contains the value + # False if it does not + def contains(self, target): + if target == self.value: + return True + elif target < self.value and self.left: + return self.left.contains(target) + elif target > self.value and self.right: + return self.right.contains(target) diff --git a/names/doubly_linked_list.py b/names/doubly_linked_list.py new file mode 100644 index 000000000..5b93565a6 --- /dev/null +++ b/names/doubly_linked_list.py @@ -0,0 +1,139 @@ +class ListNode: + def __init__(self, value, prev=None, next=None): + self.value = value + self.prev = prev + self.next = next + + """Wrap the given value in a ListNode and insert it + after this node. Note that this node could already + have a next node it is point to.""" + def insert_after(self, value): + current_next = self.next + self.next = ListNode(value, self, current_next) + if current_next: + current_next.prev = self.next + + """Wrap the given value in a ListNode and insert it + before this node. Note that this node could already + have a previous node it is point to.""" + def insert_before(self, value): + current_prev = self.prev + self.prev = ListNode(value, current_prev, self) + if current_prev: + current_prev.next = self.prev + + """Rearranges this ListNode's previous and next pointers + accordingly, effectively deleting this ListNode.""" + def delete(self): + if self.prev: + self.prev.next = self.next + if self.next: + self.next.prev = self.prev + + +"""Our doubly-linked list class. It holds references to +the list's head and tail nodes.""" +class DoublyLinkedList: + def __init__(self, node=None): + self.head = node + self.tail = node + self.length = 1 if node is not None else 0 + + def __len__(self): + return self.length + + """Wraps the given value in a ListNode and inserts it + as the new head of the list. Don't forget to handle + the old head node's previous pointer accordingly.""" + def add_to_head(self, value): + new_node = ListNode(value, None, self.head) + + if not self.head and not self.tail: + self.head = new_node + self.tail = new_node + else: + self.head.prev = new_node + self.head = new_node + + self.length += 1 + + """Removes the List's current head node, making the + current head's next node the new head of the List. + Returns the value of the removed Node.""" + def remove_from_head(self): + value = self.head.value + self.delete(self.head) + return value + + """Wraps the given value in a ListNode and inserts it + as the new tail of the list. Don't forget to handle + the old tail node's next pointer accordingly.""" + def add_to_tail(self, value): + new_node = ListNode(value, self.tail, None) + + if not self.head and not self.tail: + self.head = new_node + self.tail = new_node + else: + self.tail.next = new_node + self.tail = new_node + + self.length += 1 + + """Removes the List's current tail node, making the + current tail's previous node the new tail of the List. + Returns the value of the removed Node.""" + def remove_from_tail(self): + value = self.tail.value + self.delete(self.tail) + return value + + """Removes the input node from its current spot in the + List and inserts it as the new head node of the List.""" + def move_to_front(self, node): + if node is self.head: + return + value = node.value + self.delete(node) + self.add_to_head(value) + + """Removes the input node from its current spot in the + List and inserts it as the new tail node of the List.""" + def move_to_end(self, node): + if node is self.tail: + return + value = node.value + self.delete(node) + self.add_to_tail(value) + + """Removes a node from the list and handles cases where + the node was the head or the tail""" + def delete(self, node): + self.length -= 1 + + if self.head is self.tail: + self.head = None + self.tail = None + + elif node is self.head: + self.head = self.head.next + node.delete() + elif node is self.tail: + self.tail = self.tail.prev + node.delete() + else: + node.delete() + + """Returns the highest value currently in the list""" + def get_max(self): + if not self.head: + return None + + max_val = self.head.value + current = self.head + + while current: + if current.value > max_val: + max_val = current.value + current = current.next + return max_val \ No newline at end of file diff --git a/names/names.py b/names/names.py index ea158997f..f95e338e1 100644 --- a/names/names.py +++ b/names/names.py @@ -1,4 +1,5 @@ import time +from binary_search_tree import BSTNode start_time = time.time() @@ -11,17 +12,18 @@ f.close() duplicates = [] # Return the list of duplicates in this data structure +bst = BSTNode("") -# Replace the nested for loops below with your improvements -for name_1 in names_1: - for name_2 in names_2: - if name_1 == name_2: - duplicates.append(name_1) +for name in names_1: + bst.insert(name) + +for name in names_2: + if bst.contains(name): + duplicates.append(name) end_time = time.time() print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n") print (f"runtime: {end_time - start_time} seconds") - # ---------- Stretch Goal ----------- # Python has built-in tools that allow for a very efficient approach to this problem # What's the best time you can accomplish? Thare are no restrictions on techniques or data diff --git a/names/queue.py b/names/queue.py new file mode 100644 index 000000000..891f4d9b8 --- /dev/null +++ b/names/queue.py @@ -0,0 +1,25 @@ +from doubly_linked_list import DoublyLinkedList +import sys +sys.path.append('../doubly_linked_list') + +class Queue: + def __init__(self): + self.size = 0 + self.storage = DoublyLinkedList() + + def __len__(self): + return self.size + + def enqueue(self, value): + self.storage.add_to_tail(value) + self.size += 1 + + def dequeue(self): + if self.storage.head == None: + return None + + else: + # we need to decrement/decrease size by 1 + self.size -= 1 + # use remove_from_head() to delete the first node/the head + return self.storage.remove_from_head() diff --git a/names/stack.py b/names/stack.py new file mode 100644 index 000000000..b52dbfb8d --- /dev/null +++ b/names/stack.py @@ -0,0 +1,34 @@ +from doubly_linked_list import DoublyLinkedList +import sys +sys.path.append('../doubly_linked_list') + +class Stack: + def __init__(self): + self.size = 0 + # self.storage = ? + self.storage = DoublyLinkedList() + + def __len__(self): + return self.size + + def push(self, value): + # push means we are adding to the top/head of the DLL_Stack + # we need to increment/increase size by 1 + self.size += 1 + # use add_to_head() to add the value in a new node + # to the top/head of the DLL_Stack + self.storage.add_to_head(value) + + + def pop(self): + # In pop function, we are subtracting/removing from the top/head of the DLL_Stack + # if there is no node in storage + if self.storage.head == None: + # otherwise, return None + return None + + else: + # we will need to decrement/decrease size by 1 + self.size -= 1 + # use the function remove_from_head() to delete the last node added onto the DLL_Stack + return self.storage.remove_from_head() diff --git a/names/test_binary_search_tree.py b/names/test_binary_search_tree.py new file mode 100644 index 000000000..2bdc70922 --- /dev/null +++ b/names/test_binary_search_tree.py @@ -0,0 +1,110 @@ +import unittest +import random +import sys +import io +from binary_search_tree import BSTNode + +class BinarySearchTreeTests(unittest.TestCase): + def setUp(self): + self.bst = BSTNode(5) + + def test_insert(self): + self.bst.insert(2) + self.bst.insert(3) + self.bst.insert(7) + self.bst.insert(6) + self.assertEqual(self.bst.left.right.value, 3) + self.assertEqual(self.bst.right.left.value, 6) + + def test_handle_dupe_insert(self): + self.bst2 = BSTNode(1) + self.bst2.insert(1) + self.assertEqual(self.bst2.right.value, 1) + + def test_contains(self): + self.bst.insert(2) + self.bst.insert(3) + self.bst.insert(7) + self.assertTrue(self.bst.contains(7)) + self.assertFalse(self.bst.contains(8)) + + def test_get_max(self): + self.assertEqual(self.bst.get_max(), 5) + self.bst.insert(30) + self.assertEqual(self.bst.get_max(), 30) + self.bst.insert(300) + self.bst.insert(3) + self.assertEqual(self.bst.get_max(), 300) + + def test_for_each(self): + arr = [] + cb = lambda x: arr.append(x) + + v1 = random.randint(1, 101) + v2 = random.randint(1, 101) + v3 = random.randint(1, 101) + v4 = random.randint(1, 101) + v5 = random.randint(1, 101) + + self.bst.insert(v1) + self.bst.insert(v2) + self.bst.insert(v3) + self.bst.insert(v4) + self.bst.insert(v5) + + self.bst.for_each(cb) + + self.assertTrue(5 in arr) + self.assertTrue(v1 in arr) + self.assertTrue(v2 in arr) + self.assertTrue(v3 in arr) + self.assertTrue(v4 in arr) + self.assertTrue(v5 in arr) + + def test_print_traversals(self): + # WARNING: Tests are for Print() + # Debug calls to Print() in functions will cause failure + + stdout_ = sys.stdout # Keep previous value + sys.stdout = io.StringIO() + + self.bst = BSTNode(1) + self.bst.insert(8) + self.bst.insert(5) + self.bst.insert(7) + self.bst.insert(6) + self.bst.insert(3) + self.bst.insert(4) + self.bst.insert(2) + + self.bst.in_order_print(self.bst) + + output = sys.stdout.getvalue() + self.assertEqual(output, "1\n2\n3\n4\n5\n6\n7\n8\n") + + sys.stdout = io.StringIO() + self.bst.bft_print(self.bst) + output = sys.stdout.getvalue() + self.assertTrue(output == "1\n8\n5\n3\n7\n2\n4\n6\n" or + output == "1\n8\n5\n7\n3\n6\n4\n2\n") + + sys.stdout = io.StringIO() + self.bst.dft_print(self.bst) + output = sys.stdout.getvalue() + self.assertTrue(output == "1\n8\n5\n7\n6\n3\n4\n2\n" or + output == "1\n8\n5\n3\n2\n4\n7\n6\n") + + sys.stdout = io.StringIO() + self.bst.pre_order_dft(self.bst) + output = sys.stdout.getvalue() + self.assertEqual(output, "1\n8\n5\n3\n2\n4\n7\n6\n") + + sys.stdout = io.StringIO() + self.bst.post_order_dft(self.bst) + output = sys.stdout.getvalue() + self.assertEqual(output, "2\n4\n3\n6\n7\n5\n8\n1\n") + + sys.stdout = stdout_ # Restore stdout + +if __name__ == '__main__': + unittest.main() From 3751e68e33f5de3d8804d87765c2790fac4f04db Mon Sep 17 00:00:00 2001 From: rfamilara Date: Sun, 27 Sep 2020 22:32:31 -0500 Subject: [PATCH 2/5] Completed reverse.py The test was successful --- reverse/reverse.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/reverse/reverse.py b/reverse/reverse.py index 6116252d1..f5a3bec4d 100644 --- a/reverse/reverse.py +++ b/reverse/reverse.py @@ -39,4 +39,21 @@ def contains(self, value): return False def reverse_list(self, node, prev): - pass + # use recursion to solve this problem + # check if the list is empty + if node is None: + return "It's an empty list" + # store the node's next points to a new variable + current_next = node.get_next() + # reverse, set the node's next points to his prev + node.set_next(prev) + + # if current node is not the tail, continue the recursion, + # and reverse the points: node = current_next, prev = node... + if current_next is not None: + self.reverse_list(current_next,node) + # if the current node is the tail, set it head... + else: + self.head = node + + From 43dc57d95113958bb5e351ac7dda6cf572433663 Mon Sep 17 00:00:00 2001 From: rfamilara Date: Sun, 27 Sep 2020 22:37:13 -0500 Subject: [PATCH 3/5] Completed ring_buffer.py Tests were successful --- ring_buffer/ring_buffer.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ring_buffer/ring_buffer.py b/ring_buffer/ring_buffer.py index 37e9fb0dd..a2683f4af 100644 --- a/ring_buffer/ring_buffer.py +++ b/ring_buffer/ring_buffer.py @@ -1,9 +1,19 @@ class RingBuffer: def __init__(self, capacity): - pass + self.capacity = capacity # capacity : max number in the buffer + self.data = [] # empty storage for appending data later + self.current_pos = 0 # current position index def append(self, item): - pass + if len(self.data) < self.capacity: + self.data.append(item) + + else: + self.data[self.current_pos] = item # the oldest one's position starting from 0 + + self.current_pos += 1 # then position plus 1 + self.current_pos = self.current_pos % (self.capacity) def get(self): - pass \ No newline at end of file + # return list of elements in correct order + return self.data \ No newline at end of file From a458ecdd97672d77dbaf177eb56f0823fc1dc580 Mon Sep 17 00:00:00 2001 From: rfamilara Date: Tue, 29 Sep 2020 00:38:48 -0500 Subject: [PATCH 4/5] Fixed minor issue on names.py and bynary_search_tree.py --- names/binary_search_tree.py | 90 +++++++++++++------- names/doubly_linked_list.py | 139 ------------------------------- names/names.py | 27 +++++- names/queue.py | 25 ------ names/stack.py | 34 -------- names/test_binary_search_tree.py | 8 +- 6 files changed, 89 insertions(+), 234 deletions(-) delete mode 100644 names/doubly_linked_list.py delete mode 100644 names/queue.py delete mode 100644 names/stack.py diff --git a/names/binary_search_tree.py b/names/binary_search_tree.py index dc4c2c62e..bd908691e 100644 --- a/names/binary_search_tree.py +++ b/names/binary_search_tree.py @@ -1,31 +1,65 @@ -from queue import Queue -from stack import Stack - class BSTNode: - def __init__(self, value): - self.value = value - self.left = None - self.right = None + def __init__(self, value): + self.value = value + self.left = None + self.right = None + + def insert(self, value): + # Insertion of a key, a new key is always inserted at leaf. + # We start searching a key from root + # till we hit a leaf node. Once a leaf node is found, + # the new node is added as a child of the leaf node. + if value < self.value: + #Go Left + if not self.left: + #add as leaf + self.left = BSTNode(value) + else: + #check again + self.left.insert(value) + else: + #Go Right + if not self.right: + self.right = BSTNode(value) + else: + self.right.insert(value) + + def contains(self, target): + # Searching a key + # To search a given key in Binary Search Tree, we first compare it with root, + # if the key is present at root, we return root. If key is greater than root's + # key, we recur for right subtree of root node. Otherwise we recur for left + # subtree. + if self.value == target: + return True + if target < self.value: + if not self.left: + return False + else: + return self.left.contains(target) + else: + if not self.right: + return False + else: + return self.right.contains(target) - # Insert the given value into the tree - def insert(self, value): - if value < self.value: - if not self.left: - self.left = BSTNode(value) - else: - self.left.insert(value) - else: - if not self.right: - self.right = BSTNode(value) - else: - self.right.insert(value) + def get_max(self): + # Keep going right until you find a node without a child to the right + if not self: + return None + else: + if not self.right: + return self.value + else: + return self.right.get_max() - # Return True if the tree contains the value - # False if it does not - def contains(self, target): - if target == self.value: - return True - elif target < self.value and self.left: - return self.left.contains(target) - elif target > self.value and self.right: - return self.right.contains(target) + def for_each(self, callback): + # We need to traverse the tree similar to how the print works in the demo + # For each value append it to the array + + # Call the function + callback(self.value) + if self.left: + self.left.for_each(callback) + if self.right: + self.right.for_each(callback) \ No newline at end of file diff --git a/names/doubly_linked_list.py b/names/doubly_linked_list.py deleted file mode 100644 index 5b93565a6..000000000 --- a/names/doubly_linked_list.py +++ /dev/null @@ -1,139 +0,0 @@ -class ListNode: - def __init__(self, value, prev=None, next=None): - self.value = value - self.prev = prev - self.next = next - - """Wrap the given value in a ListNode and insert it - after this node. Note that this node could already - have a next node it is point to.""" - def insert_after(self, value): - current_next = self.next - self.next = ListNode(value, self, current_next) - if current_next: - current_next.prev = self.next - - """Wrap the given value in a ListNode and insert it - before this node. Note that this node could already - have a previous node it is point to.""" - def insert_before(self, value): - current_prev = self.prev - self.prev = ListNode(value, current_prev, self) - if current_prev: - current_prev.next = self.prev - - """Rearranges this ListNode's previous and next pointers - accordingly, effectively deleting this ListNode.""" - def delete(self): - if self.prev: - self.prev.next = self.next - if self.next: - self.next.prev = self.prev - - -"""Our doubly-linked list class. It holds references to -the list's head and tail nodes.""" -class DoublyLinkedList: - def __init__(self, node=None): - self.head = node - self.tail = node - self.length = 1 if node is not None else 0 - - def __len__(self): - return self.length - - """Wraps the given value in a ListNode and inserts it - as the new head of the list. Don't forget to handle - the old head node's previous pointer accordingly.""" - def add_to_head(self, value): - new_node = ListNode(value, None, self.head) - - if not self.head and not self.tail: - self.head = new_node - self.tail = new_node - else: - self.head.prev = new_node - self.head = new_node - - self.length += 1 - - """Removes the List's current head node, making the - current head's next node the new head of the List. - Returns the value of the removed Node.""" - def remove_from_head(self): - value = self.head.value - self.delete(self.head) - return value - - """Wraps the given value in a ListNode and inserts it - as the new tail of the list. Don't forget to handle - the old tail node's next pointer accordingly.""" - def add_to_tail(self, value): - new_node = ListNode(value, self.tail, None) - - if not self.head and not self.tail: - self.head = new_node - self.tail = new_node - else: - self.tail.next = new_node - self.tail = new_node - - self.length += 1 - - """Removes the List's current tail node, making the - current tail's previous node the new tail of the List. - Returns the value of the removed Node.""" - def remove_from_tail(self): - value = self.tail.value - self.delete(self.tail) - return value - - """Removes the input node from its current spot in the - List and inserts it as the new head node of the List.""" - def move_to_front(self, node): - if node is self.head: - return - value = node.value - self.delete(node) - self.add_to_head(value) - - """Removes the input node from its current spot in the - List and inserts it as the new tail node of the List.""" - def move_to_end(self, node): - if node is self.tail: - return - value = node.value - self.delete(node) - self.add_to_tail(value) - - """Removes a node from the list and handles cases where - the node was the head or the tail""" - def delete(self, node): - self.length -= 1 - - if self.head is self.tail: - self.head = None - self.tail = None - - elif node is self.head: - self.head = self.head.next - node.delete() - elif node is self.tail: - self.tail = self.tail.prev - node.delete() - else: - node.delete() - - """Returns the highest value currently in the list""" - def get_max(self): - if not self.head: - return None - - max_val = self.head.value - current = self.head - - while current: - if current.value > max_val: - max_val = current.value - current = current.next - return max_val \ No newline at end of file diff --git a/names/names.py b/names/names.py index f95e338e1..30538d75d 100644 --- a/names/names.py +++ b/names/names.py @@ -12,18 +12,37 @@ f.close() duplicates = [] # Return the list of duplicates in this data structure -bst = BSTNode("") -for name in names_1: - bst.insert(name) +# Replace the nested for loops below with your improvements (orginal time took ~3.5 sec(forgot to copy it)) + +bst = BSTNode(names_1[0]) + +# for x in names_1: +# bst.insert(x) + +# for name in names_2: +# if bst.contains(name): +# duplicates.append(name) + +# runtime: 0.061672210693359375 seconds + +names2_dict = {} for name in names_2: - if bst.contains(name): + names2_dict[name] = 1 + +for name in names_1: + if names2_dict.get(name) == None: + pass + else: duplicates.append(name) +# runtime: 0.00577545166015625 seconds + end_time = time.time() print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n") print (f"runtime: {end_time - start_time} seconds") + # ---------- Stretch Goal ----------- # Python has built-in tools that allow for a very efficient approach to this problem # What's the best time you can accomplish? Thare are no restrictions on techniques or data diff --git a/names/queue.py b/names/queue.py deleted file mode 100644 index 891f4d9b8..000000000 --- a/names/queue.py +++ /dev/null @@ -1,25 +0,0 @@ -from doubly_linked_list import DoublyLinkedList -import sys -sys.path.append('../doubly_linked_list') - -class Queue: - def __init__(self): - self.size = 0 - self.storage = DoublyLinkedList() - - def __len__(self): - return self.size - - def enqueue(self, value): - self.storage.add_to_tail(value) - self.size += 1 - - def dequeue(self): - if self.storage.head == None: - return None - - else: - # we need to decrement/decrease size by 1 - self.size -= 1 - # use remove_from_head() to delete the first node/the head - return self.storage.remove_from_head() diff --git a/names/stack.py b/names/stack.py deleted file mode 100644 index b52dbfb8d..000000000 --- a/names/stack.py +++ /dev/null @@ -1,34 +0,0 @@ -from doubly_linked_list import DoublyLinkedList -import sys -sys.path.append('../doubly_linked_list') - -class Stack: - def __init__(self): - self.size = 0 - # self.storage = ? - self.storage = DoublyLinkedList() - - def __len__(self): - return self.size - - def push(self, value): - # push means we are adding to the top/head of the DLL_Stack - # we need to increment/increase size by 1 - self.size += 1 - # use add_to_head() to add the value in a new node - # to the top/head of the DLL_Stack - self.storage.add_to_head(value) - - - def pop(self): - # In pop function, we are subtracting/removing from the top/head of the DLL_Stack - # if there is no node in storage - if self.storage.head == None: - # otherwise, return None - return None - - else: - # we will need to decrement/decrease size by 1 - self.size -= 1 - # use the function remove_from_head() to delete the last node added onto the DLL_Stack - return self.storage.remove_from_head() diff --git a/names/test_binary_search_tree.py b/names/test_binary_search_tree.py index 2bdc70922..40459b676 100644 --- a/names/test_binary_search_tree.py +++ b/names/test_binary_search_tree.py @@ -4,7 +4,7 @@ import io from binary_search_tree import BSTNode -class BinarySearchTreeTests(unittest.TestCase): +class BSTNOdeTests(unittest.TestCase): def setUp(self): self.bst = BSTNode(5) @@ -77,11 +77,11 @@ def test_print_traversals(self): self.bst.insert(4) self.bst.insert(2) - self.bst.in_order_print(self.bst) - output = sys.stdout.getvalue() self.assertEqual(output, "1\n2\n3\n4\n5\n6\n7\n8\n") + self.bst.in_order_print(self.bst) + sys.stdout = io.StringIO() self.bst.bft_print(self.bst) output = sys.stdout.getvalue() @@ -107,4 +107,4 @@ def test_print_traversals(self): sys.stdout = stdout_ # Restore stdout if __name__ == '__main__': - unittest.main() + unittest.main() \ No newline at end of file From bd7c9b60992bb006e5bc48cbd701a82ba61cc38d Mon Sep 17 00:00:00 2001 From: rfamilara Date: Tue, 29 Sep 2020 22:45:13 -0500 Subject: [PATCH 5/5] Checked the names.py code Finalized Tested successfully --- names/names.py | 15 +-------------- names/test_binary_search_tree.py | 2 +- 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/names/names.py b/names/names.py index 30538d75d..98f25cdb4 100644 --- a/names/names.py +++ b/names/names.py @@ -11,21 +11,10 @@ names_2 = f.read().split("\n") # List containing 10000 names f.close() -duplicates = [] # Return the list of duplicates in this data structure - -# Replace the nested for loops below with your improvements (orginal time took ~3.5 sec(forgot to copy it)) +duplicates = [] bst = BSTNode(names_1[0]) -# for x in names_1: -# bst.insert(x) - -# for name in names_2: -# if bst.contains(name): -# duplicates.append(name) - -# runtime: 0.061672210693359375 seconds - names2_dict = {} for name in names_2: @@ -37,8 +26,6 @@ else: duplicates.append(name) -# runtime: 0.00577545166015625 seconds - end_time = time.time() print (f"{len(duplicates)} duplicates:\n\n{', '.join(duplicates)}\n\n") print (f"runtime: {end_time - start_time} seconds") diff --git a/names/test_binary_search_tree.py b/names/test_binary_search_tree.py index 40459b676..95c4102d9 100644 --- a/names/test_binary_search_tree.py +++ b/names/test_binary_search_tree.py @@ -81,7 +81,7 @@ def test_print_traversals(self): self.assertEqual(output, "1\n2\n3\n4\n5\n6\n7\n8\n") self.bst.in_order_print(self.bst) - + sys.stdout = io.StringIO() self.bst.bft_print(self.bst) output = sys.stdout.getvalue()