Fix #13, PEP8-ify notebooks.

This commit is contained in:
Donne Martin 2015-07-11 15:34:52 -04:00
parent 374d67ff30
commit 04083b2011
25 changed files with 210 additions and 173 deletions

View File

@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Do you expect the return to be in reverse order too?\n", "* Do you expect the return to be in reverse order too?\n",
" * Yes\n", " * Yes\n",
"* What if one of the inputs is None?\n", "* What if one of the inputs is None?\n",
@ -169,10 +168,12 @@
"\n", "\n",
" print('Success: test_add_reverse')\n", " print('Success: test_add_reverse')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestAddReverse()\n", " test = TestAddReverse()\n",
" test.test_add_reverse()\n", " test.test_add_reverse()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -33,7 +33,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Do you expect the return to be in reverse order too?\n", "* Do you expect the return to be in reverse order too?\n",
" * Yes\n", " * Yes\n",
"* What if one of the inputs is None?\n", "* What if one of the inputs is None?\n",
@ -133,7 +132,8 @@
" new_carry = 1 if value >= 10 else 0\n", " new_carry = 1 if value >= 10 else 0\n",
" remainder = value % 10\n", " remainder = value % 10\n",
" node = Node(remainder)\n", " node = Node(remainder)\n",
" node.next = self.__add_reverse__(first_node.next if first_node is not None else None, \n", " node.next = self.__add_reverse__(\n",
" first_node.next if first_node is not None else None,\n",
" second_node.next if first_node is not None else None,\n", " second_node.next if first_node is not None else None,\n",
" new_carry)\n", " new_carry)\n",
" return node\n", " return node\n",
@ -209,10 +209,12 @@
"\n", "\n",
" print('Success: test_add_reverse')\n", " print('Success: test_add_reverse')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestAddReverse()\n", " test = TestAddReverse()\n",
" test.test_add_reverse()\n", " test.test_add_reverse()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -38,9 +38,11 @@ class TestAddReverse(object):
print('Success: test_add_reverse') print('Success: test_add_reverse')
def main(): def main():
test = TestAddReverse() test = TestAddReverse()
test.test_add_reverse() test.test_add_reverse()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* What if the final node is being deleted, for example a single node list? Do we make it a dummy with value None?\n", "* What if the final node is being deleted, for example a single node list? Do we make it a dummy with value None?\n",
" * Yes\n", " * Yes\n",
"* Can we assume we already have a linked list class that can be used for this problem?\n", "* Can we assume we already have a linked list class that can be used for this problem?\n",
@ -149,10 +148,12 @@
"\n", "\n",
" print('Success: test_delete_node')\n", " print('Success: test_delete_node')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestDeleteNode()\n", " test = TestDeleteNode()\n",
" test.test_delete_node()\n", " test.test_delete_node()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -33,7 +33,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* What if the final node is being deleted, for example a single node list? Do we make it a dummy with value None?\n", "* What if the final node is being deleted, for example a single node list? Do we make it a dummy with value None?\n",
" * Yes\n", " * Yes\n",
"* Can we assume we already have a linked list class that can be used for this problem?\n", "* Can we assume we already have a linked list class that can be used for this problem?\n",
@ -162,10 +161,12 @@
"\n", "\n",
" print('Success: test_delete_node')\n", " print('Success: test_delete_node')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestDeleteNode()\n", " test = TestDeleteNode()\n",
" test.test_delete_node()\n", " test.test_delete_node()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -26,9 +26,11 @@ class TestDeleteNode(object):
print('Success: test_delete_node') print('Success: test_delete_node')
def main(): def main():
test = TestDeleteNode() test = TestDeleteNode()
test.test_delete_node() test.test_delete_node()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Is this a singly linked list?\n", "* Is this a singly linked list?\n",
" * Yes\n", " * Yes\n",
"* Can we assume we are always passed a circular linked list?\n", "* Can we assume we are always passed a circular linked list?\n",
@ -165,10 +164,12 @@
"\n", "\n",
" print('Success: test_find_loop_start')\n", " print('Success: test_find_loop_start')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestFindLoopStart()\n", " test = TestFindLoopStart()\n",
" test.test_find_loop_start()\n", " test.test_find_loop_start()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -33,7 +33,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Is this a singly linked list?\n", "* Is this a singly linked list?\n",
" * Yes\n", " * Yes\n",
"* Can we assume we are always passed a circular linked list?\n", "* Can we assume we are always passed a circular linked list?\n",
@ -194,10 +193,12 @@
"\n", "\n",
" print('Success: test_find_loop_start')\n", " print('Success: test_find_loop_start')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestFindLoopStart()\n", " test = TestFindLoopStart()\n",
" test.test_find_loop_start()\n", " test.test_find_loop_start()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -39,9 +39,11 @@ class TestFindLoopStart(object):
print('Success: test_find_loop_start') print('Success: test_find_loop_start')
def main(): def main():
test = TestFindLoopStart() test = TestFindLoopStart()
test.test_find_loop_start() test.test_find_loop_start()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Can we assume k is a valid integer?\n", "* Can we assume k is a valid integer?\n",
" * Yes\n", " * Yes\n",
"* If k = 0, does this return the last element?\n", "* If k = 0, does this return the last element?\n",
@ -154,10 +153,12 @@
"\n", "\n",
" print('Success: test_kth_to_last_elem')\n", " print('Success: test_kth_to_last_elem')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = Test()\n", " test = Test()\n",
" test.test_kth_to_last_elem()\n", " test.test_kth_to_last_elem()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -33,7 +33,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Can we assume k is a valid integer?\n", "* Can we assume k is a valid integer?\n",
" * Yes\n", " * Yes\n",
"* If k = 0, does this return the last element?\n", "* If k = 0, does this return the last element?\n",
@ -177,10 +176,12 @@
"\n", "\n",
" print('Success: test_kth_to_last_elem')\n", " print('Success: test_kth_to_last_elem')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = Test()\n", " test = Test()\n",
" test.test_kth_to_last_elem()\n", " test.test_kth_to_last_elem()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -25,9 +25,11 @@ class Test(object):
print('Success: test_kth_to_last_elem') print('Success: test_kth_to_last_elem')
def main(): def main():
test = Test() test = Test()
test.test_kth_to_last_elem() test.test_kth_to_last_elem()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -7,6 +7,7 @@ class Node(object):
def __str__(self): def __str__(self):
return self.data return self.data
class LinkedList(object): class LinkedList(object):
def __init__(self, head=None): def __init__(self, head=None):

View File

@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Is this a singly or doubly linked list?\n", "* Is this a singly or doubly linked list?\n",
" * Singly\n", " * Singly\n",
"* Is this a circular list?\n", "* Is this a circular list?\n",
@ -119,6 +118,7 @@
" pass\n", " pass\n",
" # TODO: Implement me\n", " # TODO: Implement me\n",
"\n", "\n",
"\n",
"class LinkedList(object):\n", "class LinkedList(object):\n",
"\n", "\n",
" def __init__(self, head=None):\n", " def __init__(self, head=None):\n",
@ -284,6 +284,7 @@
"\n", "\n",
" print('Success: test_len\\n')\n", " print('Success: test_len\\n')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestLinkedList()\n", " test = TestLinkedList()\n",
" test.test_insert_to_front()\n", " test.test_insert_to_front()\n",
@ -292,6 +293,7 @@
" test.test_delete()\n", " test.test_delete()\n",
" test.test_len()\n", " test.test_len()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -33,7 +33,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Is this a singly or doubly linked list?\n", "* Is this a singly or doubly linked list?\n",
" * Singly\n", " * Singly\n",
"* Is this a circular list?\n", "* Is this a circular list?\n",
@ -196,6 +195,7 @@
" def __str__(self):\n", " def __str__(self):\n",
" return self.data\n", " return self.data\n",
"\n", "\n",
"\n",
"class LinkedList(object):\n", "class LinkedList(object):\n",
"\n", "\n",
" def __init__(self, head=None):\n", " def __init__(self, head=None):\n",
@ -416,6 +416,7 @@
"\n", "\n",
" print('Success: test_len\\n')\n", " print('Success: test_len\\n')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestLinkedList()\n", " test = TestLinkedList()\n",
" test.test_insert_to_front()\n", " test.test_insert_to_front()\n",
@ -424,6 +425,7 @@
" test.test_delete()\n", " test.test_delete()\n",
" test.test_len()\n", " test.test_len()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -103,6 +103,7 @@ class TestLinkedList(object):
print('Success: test_len\n') print('Success: test_len\n')
def main(): def main():
test = TestLinkedList() test = TestLinkedList()
test.test_insert_to_front() test.test_insert_to_front()
@ -111,5 +112,6 @@ def main():
test.test_delete() test.test_delete()
test.test_len() test.test_len()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Is a single character or number a palindrome?\n", "* Is a single character or number a palindrome?\n",
" * No\n", " * No\n",
"* Can we assume we already have a linked list class that can be used for this problem?\n", "* Can we assume we already have a linked list class that can be used for this problem?\n",
@ -161,10 +160,12 @@
"\n", "\n",
" print('Success: test_palindrome')\n", " print('Success: test_palindrome')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestPalindrome()\n", " test = TestPalindrome()\n",
" test.test_palindrome()\n", " test.test_palindrome()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -192,10 +192,12 @@
"\n", "\n",
" print('Success: test_palindrome')\n", " print('Success: test_palindrome')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestPalindrome()\n", " test = TestPalindrome()\n",
" test.test_palindrome()\n", " test.test_palindrome()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -36,9 +36,11 @@ class TestPalindrome(object):
print('Success: test_palindrome') print('Success: test_palindrome')
def main(): def main():
test = TestPalindrome() test = TestPalindrome()
test.test_palindrome() test.test_palindrome()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Can we create additional data structures?\n", "* Can we create additional data structures?\n",
" * Yes\n", " * Yes\n",
"* Do you expect the function to return a new list?\n", "* Do you expect the function to return a new list?\n",
@ -168,10 +167,12 @@
"\n", "\n",
" print('Success: test_partition')\n", " print('Success: test_partition')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestPartition()\n", " test = TestPartition()\n",
" test.test_partition()\n", " test.test_partition()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -33,7 +33,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Can we create additional data structures?\n", "* Can we create additional data structures?\n",
" * Yes\n", " * Yes\n",
"* Do you expect the function to return a new list?\n", "* Do you expect the function to return a new list?\n",
@ -193,10 +192,12 @@
"\n", "\n",
" print('Success: test_partition')\n", " print('Success: test_partition')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestPartition()\n", " test = TestPartition()\n",
" test.test_partition()\n", " test.test_partition()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -37,9 +37,11 @@ class TestPartition(object):
print('Success: test_partition') print('Success: test_partition')
def main(): def main():
test = TestPartition() test = TestPartition()
test.test_partition() test.test_partition()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Is this a singly or doubly linked list?\n", "* Is this a singly or doubly linked list?\n",
" * Singly\n", " * Singly\n",
"* Can you insert None values in the list?\n", "* Can you insert None values in the list?\n",
@ -154,11 +153,13 @@
"\n", "\n",
" print('Success: test_remove_dupes\\n')\n", " print('Success: test_remove_dupes\\n')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestRemoveDupes()\n", " test = TestRemoveDupes()\n",
" linked_list = MyLinkedList(None)\n", " linked_list = MyLinkedList(None)\n",
" test.test_remove_dupes(linked_list)\n", " test.test_remove_dupes(linked_list)\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Is this a singly or doubly linked list?\n", "* Is this a singly or doubly linked list?\n",
" * Singly\n", " * Singly\n",
"* Can you insert None values in the list?\n", "* Can you insert None values in the list?\n",
@ -204,11 +203,13 @@
"\n", "\n",
" print('Success: test_remove_dupes\\n')\n", " print('Success: test_remove_dupes\\n')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestRemoveDupes()\n", " test = TestRemoveDupes()\n",
" linked_list = MyLinkedList(None)\n", " linked_list = MyLinkedList(None)\n",
" test.test_remove_dupes(linked_list)\n", " test.test_remove_dupes(linked_list)\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -27,10 +27,12 @@ class TestRemoveDupes(object):
print('Success: test_remove_dupes\n') print('Success: test_remove_dupes\n')
def main(): def main():
test = TestRemoveDupes() test = TestRemoveDupes()
linked_list = MyLinkedList(None) linked_list = MyLinkedList(None)
test.test_remove_dupes(linked_list) test.test_remove_dupes(linked_list)
if __name__ == '__main__': if __name__ == '__main__':
main() main()