Fix #13, PEP8-ify notebooks.

This commit is contained in:
Donne Martin 2015-07-11 15:34:14 -04:00
parent 27c4a4f97c
commit 374d67ff30
18 changed files with 117 additions and 80 deletions

View File

@ -121,10 +121,12 @@
" assert_equal(func('AAABCCDDDD'), 'A3B1C2D4')\n", " assert_equal(func('AAABCCDDDD'), 'A3B1C2D4')\n",
" print('Success: test_compress')\n", " print('Success: test_compress')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestCompress()\n", " test = TestCompress()\n",
" test.test_compress(compress_string)\n", " test.test_compress(compress_string)\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -170,10 +170,12 @@
" assert_equal(func('AAABCCDDDD'), 'A3B1C2D4')\n", " assert_equal(func('AAABCCDDDD'), 'A3B1C2D4')\n",
" print('Success: test_compress')\n", " print('Success: test_compress')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestCompress()\n", " test = TestCompress()\n",
" test.test_compress(compress_string)\n", " test.test_compress(compress_string)\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -10,9 +10,11 @@ class TestCompress(object):
assert_equal(func('AAABCCDDDD'), 'A3B1C2D4') assert_equal(func('AAABCCDDDD'), 'A3B1C2D4')
print('Success: test_compress') print('Success: test_compress')
def main(): def main():
test = TestCompress() test = TestCompress()
test.test_compress(compress_string) test.test_compress(compress_string)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* For simplicity, are the keys integers only?\n", "* For simplicity, are the keys integers only?\n",
" * Yes\n", " * Yes\n",
"* For collision resolution, can we use linked lists?\n", "* For collision resolution, can we use linked lists?\n",
@ -87,6 +86,7 @@
" # TODO: Implement me\n", " # TODO: Implement me\n",
" pass\n", " pass\n",
"\n", "\n",
"\n",
"class HashTable(object):\n", "class HashTable(object):\n",
"\n", "\n",
" def __init__(self, size):\n", " def __init__(self, size):\n",
@ -174,10 +174,12 @@
"\n", "\n",
" print('Success: test_end_to_end')\n", " print('Success: test_end_to_end')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestHashMap()\n", " test = TestHashMap()\n",
" test.test_end_to_end()\n", " test.test_end_to_end()\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",
"* For simplicity, are the keys integers only?\n", "* For simplicity, are the keys integers only?\n",
" * Yes\n", " * Yes\n",
"* For collision resolution, can we use linked lists?\n", "* For collision resolution, can we use linked lists?\n",
@ -121,6 +120,7 @@
" self.key = key\n", " self.key = key\n",
" self.value = value\n", " self.value = value\n",
"\n", "\n",
"\n",
"class HashTable(object):\n", "class HashTable(object):\n",
"\n", "\n",
" def __init__(self, size):\n", " def __init__(self, size):\n",
@ -215,10 +215,12 @@
"\n", "\n",
" print('Success: test_end_to_end')\n", " print('Success: test_end_to_end')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestHashMap()\n", " test = TestHashMap()\n",
" test.test_end_to_end()\n", " test.test_end_to_end()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -37,9 +37,11 @@ class TestHashMap(object):
print('Success: test_end_to_end') print('Success: test_end_to_end')
def main(): def main():
test = TestHashMap() test = TestHashMap()
test.test_end_to_end() test.test_end_to_end()
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 the string is ASCII?\n", "* Can we assume the string is ASCII?\n",
" * Yes\n", " * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n", " * Note: Unicode strings could require special handling depending on your language\n",
@ -122,6 +121,7 @@
" assert_equal(func('a ct', 'ca t'), True)\n", " assert_equal(func('a ct', 'ca t'), True)\n",
" print('Success: test_permutation')\n", " print('Success: test_permutation')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestPermutation()\n", " test = TestPermutation()\n",
" test.test_permutation(permutations)\n", " test.test_permutation(permutations)\n",
@ -132,6 +132,7 @@
" # in the solutions file\n", " # in the solutions file\n",
" pass\n", " pass\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -35,7 +35,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Can we assume the string is ASCII?\n", "* Can we assume the string is ASCII?\n",
" * Yes\n", " * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n", " * Note: Unicode strings could require special handling depending on your language\n",
@ -147,6 +146,7 @@
" dict_chars[char] += 1\n", " dict_chars[char] += 1\n",
" return dict_chars\n", " return dict_chars\n",
"\n", "\n",
"\n",
"def permutations_alt(str1, str2):\n", "def permutations_alt(str1, str2):\n",
" if len(str1) != len(str2):\n", " if len(str1) != len(str2):\n",
" return False\n", " return False\n",
@ -191,6 +191,7 @@
" assert_equal(func('a ct', 'ca t'), True)\n", " assert_equal(func('a ct', 'ca t'), True)\n",
" print('Success: test_permutation')\n", " print('Success: test_permutation')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestPermutation()\n", " test = TestPermutation()\n",
" test.test_permutation(permutations)\n", " test.test_permutation(permutations)\n",
@ -201,6 +202,7 @@
" # in the solutions file\n", " # in the solutions file\n",
" pass\n", " pass\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -10,6 +10,7 @@ class TestPermutation(object):
assert_equal(func('a ct', 'ca t'), True) assert_equal(func('a ct', 'ca t'), True)
print('Success: test_permutation') print('Success: test_permutation')
def main(): def main():
test = TestPermutation() test = TestPermutation()
test.test_permutation(permutations) test.test_permutation(permutations)
@ -20,5 +21,6 @@ def main():
# in the solutions file # in the solutions file
pass pass
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Can I assume the string is ASCII?\n", "* Can I assume the string is ASCII?\n",
" * Yes\n", " * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n", " * Note: Unicode strings could require special handling depending on your language\n",
@ -117,14 +116,17 @@
" def test_reverse(self):\n", " def test_reverse(self):\n",
" assert_equal(list_of_chars(None), None)\n", " assert_equal(list_of_chars(None), None)\n",
" assert_equal(list_of_chars(['']), [''])\n", " assert_equal(list_of_chars(['']), [''])\n",
" assert_equal(list_of_chars(['f', 'o', 'o', ' ', 'b', 'a', 'r']), \n", " assert_equal(list_of_chars(\n",
" ['f', 'o', 'o', ' ', 'b', 'a', 'r']),\n",
" ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n", " ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
" print('Success: test_reverse')\n", " print('Success: test_reverse')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestReverse()\n", " test = TestReverse()\n",
" test.test_reverse()\n", " test.test_reverse()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -126,6 +126,7 @@
" return None\n", " return None\n",
" return string[::-1]\n", " return string[::-1]\n",
"\n", "\n",
"\n",
"def reverse_string_alt2(string):\n", "def reverse_string_alt2(string):\n",
" if string is None:\n", " if string is None:\n",
" return None\n", " return None\n",
@ -164,14 +165,17 @@
" def test_reverse(self):\n", " def test_reverse(self):\n",
" assert_equal(list_of_chars(None), None)\n", " assert_equal(list_of_chars(None), None)\n",
" assert_equal(list_of_chars(['']), [''])\n", " assert_equal(list_of_chars(['']), [''])\n",
" assert_equal(list_of_chars(['f', 'o', 'o', ' ', 'b', 'a', 'r']), \n", " assert_equal(list_of_chars(\n",
" ['f', 'o', 'o', ' ', 'b', 'a', 'r']),\n",
" ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n", " ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n",
" print('Success: test_reverse')\n", " print('Success: test_reverse')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestReverse()\n", " test = TestReverse()\n",
" test.test_reverse()\n", " test.test_reverse()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -6,13 +6,16 @@ class TestReverse(object):
def test_reverse(self): def test_reverse(self):
assert_equal(list_of_chars(None), None) assert_equal(list_of_chars(None), None)
assert_equal(list_of_chars(['']), ['']) assert_equal(list_of_chars(['']), [''])
assert_equal(list_of_chars(['f', 'o', 'o', ' ', 'b', 'a', 'r']), assert_equal(list_of_chars(
['f', 'o', 'o', ' ', 'b', 'a', 'r']),
['r', 'a', 'b', ' ', 'o', 'o', 'f']) ['r', 'a', 'b', ' ', 'o', 'o', 'f'])
print('Success: test_reverse') print('Success: test_reverse')
def main(): def main():
test = TestReverse() test = TestReverse()
test.test_reverse() test.test_reverse()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Can you assume the string is ASCII?\n", "* Can you assume the string is ASCII?\n",
" * Yes\n", " * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n", " * Note: Unicode strings could require special handling depending on your language\n",
@ -85,6 +84,7 @@
" # TODO: Implement me\n", " # TODO: Implement me\n",
" pass\n", " pass\n",
"\n", "\n",
"\n",
"def is_rotation(s1, s2):\n", "def is_rotation(s1, s2):\n",
" # TODO: Implement me\n", " # TODO: Implement me\n",
" # Call is_substring only once\n", " # Call is_substring only once\n",
@ -129,10 +129,12 @@
" assert_equal(is_rotation('foobarbaz', 'barbazfoo'), True)\n", " assert_equal(is_rotation('foobarbaz', 'barbazfoo'), True)\n",
" print('Success: test_rotation')\n", " print('Success: test_rotation')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestRotation()\n", " test = TestRotation()\n",
" test.test_rotation()\n", " test.test_rotation()\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",
"* Can you assume the string is ASCII?\n", "* Can you assume the string is ASCII?\n",
" * Yes\n", " * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n", " * Note: Unicode strings could require special handling depending on your language\n",
@ -94,6 +93,7 @@
"def is_substring(s1, s2):\n", "def is_substring(s1, s2):\n",
" return s1 in s2\n", " return s1 in s2\n",
"\n", "\n",
"\n",
"def is_rotation(s1, s2):\n", "def is_rotation(s1, s2):\n",
" if s1 is None or s2 is None:\n", " if s1 is None or s2 is None:\n",
" return False\n", " return False\n",
@ -140,10 +140,12 @@
" assert_equal(is_rotation('foobarbaz', 'barbazfoo'), True)\n", " assert_equal(is_rotation('foobarbaz', 'barbazfoo'), True)\n",
" print('Success: test_rotation')\n", " print('Success: test_rotation')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestRotation()\n", " test = TestRotation()\n",
" test.test_rotation()\n", " test.test_rotation()\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -11,9 +11,11 @@ class TestRotation(object):
assert_equal(is_rotation('foobarbaz', 'barbazfoo'), True) assert_equal(is_rotation('foobarbaz', 'barbazfoo'), True)
print('Success: test_rotation') print('Success: test_rotation')
def main(): def main():
test = TestRotation() test = TestRotation()
test.test_rotation() test.test_rotation()
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -9,6 +9,7 @@ class TestUniqueChars(object):
assert_equal(func('bar'), True) assert_equal(func('bar'), True)
print('Success: test_unique_chars') print('Success: test_unique_chars')
def main(): def main():
test = TestUniqueChars() test = TestUniqueChars()
test.test_unique_chars(unique_chars) test.test_unique_chars(unique_chars)
@ -20,5 +21,6 @@ def main():
# in the solutions file # in the solutions file
pass pass
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -34,7 +34,6 @@
"source": [ "source": [
"## Constraints\n", "## Constraints\n",
"\n", "\n",
"* Can you assume the string is ASCII?\n", "* Can you assume the string is ASCII?\n",
" * Yes\n", " * Yes\n",
" * Note: Unicode strings could require special handling depending on your language\n", " * Note: Unicode strings could require special handling depending on your language\n",
@ -118,6 +117,7 @@
" assert_equal(func('bar'), True)\n", " assert_equal(func('bar'), True)\n",
" print('Success: test_unique_chars')\n", " print('Success: test_unique_chars')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestUniqueChars()\n", " test = TestUniqueChars()\n",
" test.test_unique_chars(unique_chars)\n", " test.test_unique_chars(unique_chars)\n",
@ -129,6 +129,7 @@
" # in the solutions file\n", " # in the solutions file\n",
" pass\n", " pass\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]

View File

@ -219,6 +219,7 @@
" assert_equal(func('bar'), True)\n", " assert_equal(func('bar'), True)\n",
" print('Success: test_unique_chars')\n", " print('Success: test_unique_chars')\n",
"\n", "\n",
"\n",
"def main():\n", "def main():\n",
" test = TestUniqueChars()\n", " test = TestUniqueChars()\n",
" test.test_unique_chars(unique_chars)\n", " test.test_unique_chars(unique_chars)\n",
@ -230,6 +231,7 @@
" # in the solutions file\n", " # in the solutions file\n",
" pass\n", " pass\n",
"\n", "\n",
"\n",
"if __name__ == '__main__':\n", "if __name__ == '__main__':\n",
" main()" " main()"
] ]
@ -258,21 +260,21 @@
], ],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python 2",
"language": "python", "language": "python",
"name": "python3" "name": "python2"
}, },
"language_info": { "language_info": {
"codemirror_mode": { "codemirror_mode": {
"name": "ipython", "name": "ipython",
"version": 3 "version": 2
}, },
"file_extension": ".py", "file_extension": ".py",
"mimetype": "text/x-python", "mimetype": "text/x-python",
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython2",
"version": "3.4.3" "version": "2.7.10"
} }
}, },
"nbformat": 4, "nbformat": 4,