mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-11 03:48:03 +00:00
Fix #13, PEP8-ify notebooks.
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
class Node(object):
|
||||
|
||||
|
||||
def __init__(self, data):
|
||||
self.data = data
|
||||
self.next = None
|
||||
|
||||
|
||||
class Queue(object):
|
||||
|
||||
|
||||
def __init__(self):
|
||||
self.first = None
|
||||
self.last = None
|
||||
@@ -23,7 +24,7 @@ class Queue(object):
|
||||
# Empty list
|
||||
if self.first is None and self.last is None:
|
||||
return None
|
||||
|
||||
|
||||
# Remove only element from a one element list
|
||||
elif self.first == self.last:
|
||||
data = self.first.data
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* If there is one item in the list, do you expect the first and last pointers to both point to it?\n",
|
||||
" * Yes\n",
|
||||
"* If there are no items on the list, do you expect the first and last pointers to be None?\n",
|
||||
@@ -87,13 +86,14 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class Node(object):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def __init__(self, data):\n",
|
||||
" # TODO: Implement me\n",
|
||||
" pass\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class Queue(object):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def __init__(self):\n",
|
||||
" # TODO: Implement me\n",
|
||||
" pass\n",
|
||||
@@ -131,7 +131,7 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestQueue(object):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" # TODO: It would be better if we had unit tests for each\n",
|
||||
" # method in addition to the following end-to-end test\n",
|
||||
" def test_end_to_end(self):\n",
|
||||
@@ -154,13 +154,15 @@
|
||||
" assert_equal(queue.dequeue(), 2)\n",
|
||||
" assert_equal(queue.dequeue(), 3)\n",
|
||||
" assert_equal(queue.dequeue(), 4)\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" print('Success: test_end_to_end')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestQueue()\n",
|
||||
" test.test_end_to_end()\n",
|
||||
" \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
"source": [
|
||||
"## Constraints\n",
|
||||
"\n",
|
||||
|
||||
"* If there is one item in the list, do you expect the first and last pointers to both point to it?\n",
|
||||
" * Yes\n",
|
||||
"* If there are no items on the list, do you expect the first and last pointers to be None?\n",
|
||||
@@ -118,13 +117,14 @@
|
||||
"source": [
|
||||
"%%writefile queue_list.py\n",
|
||||
"class Node(object):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def __init__(self, data):\n",
|
||||
" self.data = data\n",
|
||||
" self.next = None\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class Queue(object):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" def __init__(self):\n",
|
||||
" self.first = None\n",
|
||||
" self.last = None\n",
|
||||
@@ -142,7 +142,7 @@
|
||||
" # Empty list\n",
|
||||
" if self.first is None and self.last is None:\n",
|
||||
" return None\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" # Remove only element from a one element list\n",
|
||||
" elif self.first == self.last:\n",
|
||||
" data = self.first.data\n",
|
||||
@@ -195,7 +195,7 @@
|
||||
"\n",
|
||||
"\n",
|
||||
"class TestQueue(object):\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" # TODO: It would be better if we had unit tests for each\n",
|
||||
" # method in addition to the following end-to-end test\n",
|
||||
" def test_end_to_end(self):\n",
|
||||
@@ -218,13 +218,15 @@
|
||||
" assert_equal(queue.dequeue(), 2)\n",
|
||||
" assert_equal(queue.dequeue(), 3)\n",
|
||||
" assert_equal(queue.dequeue(), 4)\n",
|
||||
" \n",
|
||||
"\n",
|
||||
" print('Success: test_end_to_end')\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def main():\n",
|
||||
" test = TestQueue()\n",
|
||||
" test.test_end_to_end()\n",
|
||||
" \n",
|
||||
"\n",
|
||||
"\n",
|
||||
"if __name__ == '__main__':\n",
|
||||
" main()"
|
||||
]
|
||||
|
||||
@@ -2,7 +2,7 @@ from nose.tools import assert_equal
|
||||
|
||||
|
||||
class TestQueue(object):
|
||||
|
||||
|
||||
# TODO: It would be better if we had unit tests for each
|
||||
# method in addition to the following end-to-end test
|
||||
def test_end_to_end(self):
|
||||
@@ -25,12 +25,14 @@ class TestQueue(object):
|
||||
assert_equal(queue.dequeue(), 2)
|
||||
assert_equal(queue.dequeue(), 3)
|
||||
assert_equal(queue.dequeue(), 4)
|
||||
|
||||
|
||||
print('Success: test_end_to_end')
|
||||
|
||||
|
||||
def main():
|
||||
test = TestQueue()
|
||||
test.test_end_to_end()
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user