mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-08 02:18:03 +00:00
Fix #13, PEP8-ify notebooks.
This commit is contained in:
@@ -33,7 +33,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* Is this a singly or doubly linked list?\n",
|
||||
" * Singly\n",
|
||||
"* Is this a circular list?\n",
|
||||
@@ -188,16 +187,17 @@
|
||||
"source": [
|
||||
"%%writefile linked_list.py\n",
|
||||
"class Node(object):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def __init__(self, data, next_node=None):\n",
|
||||
" self.next = next_node\n",
|
||||
" self.data = data\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def __str__(self):\n",
|
||||
" return self.data\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class LinkedList(object):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def __init__(self, head=None):\n",
|
||||
" self.head = head\n",
|
||||
"\n",
|
||||
@@ -208,7 +208,7 @@
|
||||
" counter += 1\n",
|
||||
" curr = curr.next\n",
|
||||
" return counter\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def insert_to_front(self, data):\n",
|
||||
" if data is None:\n",
|
||||
" return\n",
|
||||
@@ -219,7 +219,7 @@
|
||||
" node.next = self.head\n",
|
||||
" self.head = node\n",
|
||||
" return node\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def append(self, data, next_node=None):\n",
|
||||
" if data is None:\n",
|
||||
" return\n",
|
||||
@@ -232,7 +232,7 @@
|
||||
" curr_node = curr_node.next\n",
|
||||
" curr_node.next = node\n",
|
||||
" return node\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def find(self, data):\n",
|
||||
" if data is None:\n",
|
||||
" return\n",
|
||||
@@ -245,7 +245,7 @@
|
||||
" else:\n",
|
||||
" curr_node = curr_node.next\n",
|
||||
" return\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def delete(self, data):\n",
|
||||
" if data is None:\n",
|
||||
" return\n",
|
||||
@@ -315,7 +315,7 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestLinkedList(object):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def test_insert_to_front(self):\n",
|
||||
" print('Test: insert_to_front on an empty list')\n",
|
||||
" linked_list = LinkedList(None)\n",
|
||||
@@ -330,9 +330,9 @@
|
||||
" linked_list.insert_to_front('a')\n",
|
||||
" linked_list.insert_to_front('bc')\n",
|
||||
" assert_equal(linked_list.get_all_data(), ['bc', 'a', 10])\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" print('Success: test_insert_to_front\\n')\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def test_append(self):\n",
|
||||
" print('Test: append on an empty list')\n",
|
||||
" linked_list = LinkedList(None)\n",
|
||||
@@ -347,9 +347,9 @@
|
||||
" linked_list.append('a')\n",
|
||||
" linked_list.append('bc')\n",
|
||||
" assert_equal(linked_list.get_all_data(), [10, 'a', 'bc'])\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" print('Success: test_append\\n')\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def test_find(self):\n",
|
||||
" print('Test: find on an empty list')\n",
|
||||
" linked_list = LinkedList(None)\n",
|
||||
@@ -373,9 +373,9 @@
|
||||
" print('Test: find general case with no matches')\n",
|
||||
" node = linked_list.find('aaa')\n",
|
||||
" assert_equal(node, None)\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" print('Success: test_find\\n')\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def test_delete(self):\n",
|
||||
" print('Test: delete on an empty list')\n",
|
||||
" linked_list = LinkedList(None)\n",
|
||||
@@ -399,9 +399,9 @@
|
||||
" print('Test: delete general case with no matches')\n",
|
||||
" linked_list.delete('aa')\n",
|
||||
" assert_equal(linked_list.get_all_data(), ['bc', 10])\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" print('Success: test_delete\\n')\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def test_len(self):\n",
|
||||
" print('Test: len on an empty list')\n",
|
||||
" linked_list = LinkedList(None)\n",
|
||||
@@ -413,9 +413,10 @@
|
||||
" linked_list.insert_to_front('a')\n",
|
||||
" linked_list.insert_to_front('bc')\n",
|
||||
" assert_equal(len(linked_list), 3)\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" print('Success: test_len\\n')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestLinkedList()\n",
|
||||
" test.test_insert_to_front()\n",
|
||||
@@ -423,7 +424,8 @@
|
||||
" test.test_find()\n",
|
||||
" test.test_delete()\n",
|
||||
" test.test_len()\n",
|
||||
" \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user