diff --git a/arrays_strings/compress/compress_challenge.ipynb b/arrays_strings/compress/compress_challenge.ipynb index 727981d..fb17544 100644 --- a/arrays_strings/compress/compress_challenge.ipynb +++ b/arrays_strings/compress/compress_challenge.ipynb @@ -113,7 +113,7 @@ "\n", "\n", "class TestCompress(object):\n", - " \n", + "\n", " def test_compress(self, func):\n", " assert_equal(func(None), None)\n", " assert_equal(func(''), '')\n", @@ -121,10 +121,12 @@ " assert_equal(func('AAABCCDDDD'), 'A3B1C2D4')\n", " print('Success: test_compress')\n", "\n", + "\n", "def main():\n", " test = TestCompress()\n", " test.test_compress(compress_string)\n", "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/arrays_strings/compress/compress_solution.ipynb b/arrays_strings/compress/compress_solution.ipynb index 5fab2c1..aa11798 100644 --- a/arrays_strings/compress/compress_solution.ipynb +++ b/arrays_strings/compress/compress_solution.ipynb @@ -100,7 +100,7 @@ "def compress_string(string):\n", " if string is None or len(string) == 0:\n", " return string\n", - " \n", + "\n", " # Calculate the size of the compressed string\n", " size = 0\n", " last_char = string[0]\n", @@ -109,8 +109,8 @@ " size += 2\n", " last_char = char\n", " size += 2\n", - " \n", - " # If the compressed string size is greater than \n", + "\n", + " # If the compressed string size is greater than\n", " # or equal to string size, return original string\n", " if size >= len(string):\n", " return string\n", @@ -129,7 +129,7 @@ " last_char = char\n", " compressed_string.append(last_char)\n", " compressed_string.append(str(count))\n", - " \n", + "\n", " # Convert the characters in the list to a string\n", " return \"\".join(compressed_string)" ] @@ -162,7 +162,7 @@ "\n", "\n", "class TestCompress(object):\n", - " \n", + "\n", " def test_compress(self, func):\n", " assert_equal(func(None), None)\n", " assert_equal(func(''), '')\n", @@ -170,10 +170,12 @@ " assert_equal(func('AAABCCDDDD'), 'A3B1C2D4')\n", " print('Success: test_compress')\n", "\n", + "\n", "def main():\n", " test = TestCompress()\n", " test.test_compress(compress_string)\n", "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/arrays_strings/compress/test_compress.py b/arrays_strings/compress/test_compress.py index 4865a33..7ce5142 100644 --- a/arrays_strings/compress/test_compress.py +++ b/arrays_strings/compress/test_compress.py @@ -2,7 +2,7 @@ from nose.tools import assert_equal class TestCompress(object): - + def test_compress(self, func): assert_equal(func(None), None) assert_equal(func(''), '') @@ -10,9 +10,11 @@ class TestCompress(object): assert_equal(func('AAABCCDDDD'), 'A3B1C2D4') print('Success: test_compress') + def main(): test = TestCompress() test.test_compress(compress_string) + if __name__ == '__main__': main() \ No newline at end of file diff --git a/arrays_strings/hash_map/hash_map_challenge.ipynb b/arrays_strings/hash_map/hash_map_challenge.ipynb index ddfa5e8..fc496e4 100644 --- a/arrays_strings/hash_map/hash_map_challenge.ipynb +++ b/arrays_strings/hash_map/hash_map_challenge.ipynb @@ -34,7 +34,6 @@ "source": [ "## Constraints\n", "\n", - "* For simplicity, are the keys integers only?\n", " * Yes\n", "* For collision resolution, can we use linked lists?\n", @@ -82,13 +81,14 @@ "outputs": [], "source": [ "class Item(object):\n", - " \n", + "\n", " def __init__(self, key, value):\n", " # TODO: Implement me\n", " pass\n", "\n", + "\n", "class HashTable(object):\n", - " \n", + "\n", " def __init__(self, size):\n", " # TODO: Implement me\n", " pass\n", @@ -139,45 +139,47 @@ "\n", "\n", "class TestHashMap(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", " hash_table = HashTable(10)\n", - " \n", + "\n", " print(\"Test: get on an empty hash table index\")\n", " assert_equal(hash_table.get(0), None)\n", - " \n", + "\n", " print(\"Test: set on an empty hash table index\")\n", " hash_table.set(0, 'foo')\n", " assert_equal(hash_table.get(0), 'foo')\n", " hash_table.set(1, 'bar')\n", " assert_equal(hash_table.get(1), 'bar')\n", - " \n", + "\n", " print(\"Test: set on a non empty hash table index\")\n", " hash_table.set(10, 'foo2')\n", " assert_equal(hash_table.get(0), 'foo')\n", " assert_equal(hash_table.get(10), 'foo2')\n", - " \n", + "\n", " print(\"Test: set on a key that already exists\")\n", " hash_table.set(10, 'foo3')\n", " assert_equal(hash_table.get(0), 'foo')\n", " assert_equal(hash_table.get(10), 'foo3')\n", - " \n", + "\n", " print(\"Test: remove on a key that already exists\")\n", " hash_table.remove(10)\n", " assert_equal(hash_table.get(0), 'foo')\n", " assert_equal(hash_table.get(10), None)\n", - " \n", + "\n", " print(\"Test: remove on a key that doesn't exist\")\n", " hash_table.remove(-1)\n", - " \n", + "\n", " print('Success: test_end_to_end')\n", "\n", + "\n", "def main():\n", " test = TestHashMap()\n", " test.test_end_to_end()\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/arrays_strings/hash_map/hash_map_solution.ipynb b/arrays_strings/hash_map/hash_map_solution.ipynb index 32710e9..b98dc15 100644 --- a/arrays_strings/hash_map/hash_map_solution.ipynb +++ b/arrays_strings/hash_map/hash_map_solution.ipynb @@ -33,7 +33,6 @@ "source": [ "## Constraints\n", "\n", - "* For simplicity, are the keys integers only?\n", " * Yes\n", "* For collision resolution, can we use linked lists?\n", @@ -116,13 +115,14 @@ "outputs": [], "source": [ "class Item(object):\n", - " \n", + "\n", " def __init__(self, key, value):\n", " self.key = key\n", " self.value = value\n", "\n", + "\n", "class HashTable(object):\n", - " \n", + "\n", " def __init__(self, size):\n", " self.size = size\n", " self.table = [[] for _ in range(self.size)]\n", @@ -180,45 +180,47 @@ "\n", "\n", "class TestHashMap(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", " hash_table = HashTable(10)\n", - " \n", + "\n", " print(\"Test: get on an empty hash table index\")\n", " assert_equal(hash_table.get(0), None)\n", - " \n", + "\n", " print(\"Test: set on an empty hash table index\")\n", " hash_table.set(0, 'foo')\n", " assert_equal(hash_table.get(0), 'foo')\n", " hash_table.set(1, 'bar')\n", " assert_equal(hash_table.get(1), 'bar')\n", - " \n", + "\n", " print(\"Test: set on a non empty hash table index\")\n", " hash_table.set(10, 'foo2')\n", " assert_equal(hash_table.get(0), 'foo')\n", " assert_equal(hash_table.get(10), 'foo2')\n", - " \n", + "\n", " print(\"Test: set on a key that already exists\")\n", " hash_table.set(10, 'foo3')\n", " assert_equal(hash_table.get(0), 'foo')\n", " assert_equal(hash_table.get(10), 'foo3')\n", - " \n", + "\n", " print(\"Test: remove on a key that already exists\")\n", " hash_table.remove(10)\n", " assert_equal(hash_table.get(0), 'foo')\n", " assert_equal(hash_table.get(10), None)\n", - " \n", + "\n", " print(\"Test: remove on a key that doesn't exist\")\n", " hash_table.remove(-1)\n", - " \n", + "\n", " print('Success: test_end_to_end')\n", "\n", + "\n", "def main():\n", " test = TestHashMap()\n", " test.test_end_to_end()\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/arrays_strings/hash_map/test_hash_map.py b/arrays_strings/hash_map/test_hash_map.py index 2ed8a77..486f2c4 100644 --- a/arrays_strings/hash_map/test_hash_map.py +++ b/arrays_strings/hash_map/test_hash_map.py @@ -2,44 +2,46 @@ from nose.tools import assert_equal class TestHashMap(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): hash_table = HashTable(10) - + print("Test: get on an empty hash table index") assert_equal(hash_table.get(0), None) - + print("Test: set on an empty hash table index") hash_table.set(0, 'foo') assert_equal(hash_table.get(0), 'foo') hash_table.set(1, 'bar') assert_equal(hash_table.get(1), 'bar') - + print("Test: set on a non empty hash table index") hash_table.set(10, 'foo2') assert_equal(hash_table.get(0), 'foo') assert_equal(hash_table.get(10), 'foo2') - + print("Test: set on a key that already exists") hash_table.set(10, 'foo3') assert_equal(hash_table.get(0), 'foo') assert_equal(hash_table.get(10), 'foo3') - + print("Test: remove on a key that already exists") hash_table.remove(10) assert_equal(hash_table.get(0), 'foo') assert_equal(hash_table.get(10), None) - + print("Test: remove on a key that doesn't exist") hash_table.remove(-1) - + print('Success: test_end_to_end') + def main(): test = TestHashMap() test.test_end_to_end() - + + if __name__ == '__main__': main() \ No newline at end of file diff --git a/arrays_strings/permutation/permutation_challenge.ipynb b/arrays_strings/permutation/permutation_challenge.ipynb index f6f43a3..ce31923 100644 --- a/arrays_strings/permutation/permutation_challenge.ipynb +++ b/arrays_strings/permutation/permutation_challenge.ipynb @@ -34,7 +34,6 @@ "source": [ "## Constraints\n", "\n", - "* Can we assume the string is ASCII?\n", " * Yes\n", " * Note: Unicode strings could require special handling depending on your language\n", @@ -114,7 +113,7 @@ "\n", "\n", "class TestPermutation(object):\n", - " \n", + "\n", " def test_permutation(self, func):\n", " assert_equal(func('', 'foo'), False)\n", " assert_equal(func('Nib', 'bin'), False)\n", @@ -122,6 +121,7 @@ " assert_equal(func('a ct', 'ca t'), True)\n", " print('Success: test_permutation')\n", "\n", + "\n", "def main():\n", " test = TestPermutation()\n", " test.test_permutation(permutations)\n", @@ -131,7 +131,8 @@ " # Alternate solutions are only defined\n", " # in the solutions file\n", " pass\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/arrays_strings/permutation/permutation_solution.ipynb b/arrays_strings/permutation/permutation_solution.ipynb index 6eb4e58..0b1bd0c 100644 --- a/arrays_strings/permutation/permutation_solution.ipynb +++ b/arrays_strings/permutation/permutation_solution.ipynb @@ -35,7 +35,6 @@ "source": [ "## Constraints\n", "\n", - "* Can we assume the string is ASCII?\n", " * Yes\n", " * Note: Unicode strings could require special handling depending on your language\n", @@ -147,6 +146,7 @@ " dict_chars[char] += 1\n", " return dict_chars\n", "\n", + "\n", "def permutations_alt(str1, str2):\n", " if len(str1) != len(str2):\n", " return False\n", @@ -183,7 +183,7 @@ "\n", "\n", "class TestPermutation(object):\n", - " \n", + "\n", " def test_permutation(self, func):\n", " assert_equal(func('', 'foo'), False)\n", " assert_equal(func('Nib', 'bin'), False)\n", @@ -191,6 +191,7 @@ " assert_equal(func('a ct', 'ca t'), True)\n", " print('Success: test_permutation')\n", "\n", + "\n", "def main():\n", " test = TestPermutation()\n", " test.test_permutation(permutations)\n", @@ -200,7 +201,8 @@ " # Alternate solutions are only defined\n", " # in the solutions file\n", " pass\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/arrays_strings/permutation/test_permutation_solution.py b/arrays_strings/permutation/test_permutation_solution.py index 430fa81..9e14427 100644 --- a/arrays_strings/permutation/test_permutation_solution.py +++ b/arrays_strings/permutation/test_permutation_solution.py @@ -2,7 +2,7 @@ from nose.tools import assert_equal class TestPermutation(object): - + def test_permutation(self, func): assert_equal(func('', 'foo'), False) assert_equal(func('Nib', 'bin'), False) @@ -10,6 +10,7 @@ class TestPermutation(object): assert_equal(func('a ct', 'ca t'), True) print('Success: test_permutation') + def main(): test = TestPermutation() test.test_permutation(permutations) @@ -19,6 +20,7 @@ def main(): # Alternate solutions are only defined # in the solutions file pass - + + if __name__ == '__main__': main() \ No newline at end of file diff --git a/arrays_strings/reverse_string/reverse_string_challenge.ipynb b/arrays_strings/reverse_string/reverse_string_challenge.ipynb index c59e6ba..499a0de 100644 --- a/arrays_strings/reverse_string/reverse_string_challenge.ipynb +++ b/arrays_strings/reverse_string/reverse_string_challenge.ipynb @@ -34,7 +34,6 @@ "source": [ "## Constraints\n", "\n", - "* Can I assume the string is ASCII?\n", " * Yes\n", " * Note: Unicode strings could require special handling depending on your language\n", @@ -113,18 +112,21 @@ "\n", "\n", "class TestReverse(object):\n", - " \n", + "\n", " def test_reverse(self):\n", " assert_equal(list_of_chars(None), None)\n", " assert_equal(list_of_chars(['']), [''])\n", - " assert_equal(list_of_chars(['f', 'o', 'o', ' ', 'b', 'a', 'r']), \n", - " ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n", + " assert_equal(list_of_chars(\n", + " ['f', 'o', 'o', ' ', 'b', 'a', 'r']),\n", + " ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n", " print('Success: test_reverse')\n", "\n", + "\n", "def main():\n", " test = TestReverse()\n", " test.test_reverse()\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/arrays_strings/reverse_string/reverse_string_solution.ipynb b/arrays_strings/reverse_string/reverse_string_solution.ipynb index 05f6a82..73c3325 100644 --- a/arrays_strings/reverse_string/reverse_string_solution.ipynb +++ b/arrays_strings/reverse_string/reverse_string_solution.ipynb @@ -126,9 +126,10 @@ " return None\n", " return string[::-1]\n", "\n", + "\n", "def reverse_string_alt2(string):\n", " if string is None:\n", - " return None \n", + " return None\n", " return ''.join(reversed(string))" ] }, @@ -160,18 +161,21 @@ "\n", "\n", "class TestReverse(object):\n", - " \n", + "\n", " def test_reverse(self):\n", " assert_equal(list_of_chars(None), None)\n", " assert_equal(list_of_chars(['']), [''])\n", - " assert_equal(list_of_chars(['f', 'o', 'o', ' ', 'b', 'a', 'r']), \n", - " ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n", + " assert_equal(list_of_chars(\n", + " ['f', 'o', 'o', ' ', 'b', 'a', 'r']),\n", + " ['r', 'a', 'b', ' ', 'o', 'o', 'f'])\n", " print('Success: test_reverse')\n", "\n", + "\n", "def main():\n", " test = TestReverse()\n", " test.test_reverse()\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/arrays_strings/reverse_string/test_reverse_string.py b/arrays_strings/reverse_string/test_reverse_string.py index 7cbc2df..688bff7 100644 --- a/arrays_strings/reverse_string/test_reverse_string.py +++ b/arrays_strings/reverse_string/test_reverse_string.py @@ -2,17 +2,20 @@ from nose.tools import assert_equal class TestReverse(object): - + def test_reverse(self): assert_equal(list_of_chars(None), None) assert_equal(list_of_chars(['']), ['']) - assert_equal(list_of_chars(['f', 'o', 'o', ' ', 'b', 'a', 'r']), - ['r', 'a', 'b', ' ', 'o', 'o', 'f']) + assert_equal(list_of_chars( + ['f', 'o', 'o', ' ', 'b', 'a', 'r']), + ['r', 'a', 'b', ' ', 'o', 'o', 'f']) print('Success: test_reverse') + def main(): test = TestReverse() test.test_reverse() - + + if __name__ == '__main__': main() \ No newline at end of file diff --git a/arrays_strings/rotation/rotation_challenge.ipynb b/arrays_strings/rotation/rotation_challenge.ipynb index e66ebe3..3599298 100644 --- a/arrays_strings/rotation/rotation_challenge.ipynb +++ b/arrays_strings/rotation/rotation_challenge.ipynb @@ -34,7 +34,6 @@ "source": [ "## Constraints\n", "\n", - "* Can you assume the string is ASCII?\n", " * Yes\n", " * Note: Unicode strings could require special handling depending on your language\n", @@ -85,6 +84,7 @@ " # TODO: Implement me\n", " pass\n", "\n", + "\n", "def is_rotation(s1, s2):\n", " # TODO: Implement me\n", " # Call is_substring only once\n", @@ -120,7 +120,7 @@ "\n", "\n", "class TestRotation(object):\n", - " \n", + "\n", " def test_rotation(self):\n", " assert_equal(is_rotation('o', 'oo'), False)\n", " assert_equal(is_rotation(None, 'foo'), False)\n", @@ -129,10 +129,12 @@ " assert_equal(is_rotation('foobarbaz', 'barbazfoo'), True)\n", " print('Success: test_rotation')\n", "\n", + "\n", "def main():\n", " test = TestRotation()\n", " test.test_rotation()\n", "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/arrays_strings/rotation/rotation_solution.ipynb b/arrays_strings/rotation/rotation_solution.ipynb index 16b2d72..2c8cbf7 100644 --- a/arrays_strings/rotation/rotation_solution.ipynb +++ b/arrays_strings/rotation/rotation_solution.ipynb @@ -34,7 +34,6 @@ "source": [ "## Constraints\n", "\n", - "* Can you assume the string is ASCII?\n", " * Yes\n", " * Note: Unicode strings could require special handling depending on your language\n", @@ -91,9 +90,10 @@ }, "outputs": [], "source": [ - "def is_substring(s1, s2): \n", + "def is_substring(s1, s2):\n", " return s1 in s2\n", "\n", + "\n", "def is_rotation(s1, s2):\n", " if s1 is None or s2 is None:\n", " return False\n", @@ -131,7 +131,7 @@ "\n", "\n", "class TestRotation(object):\n", - " \n", + "\n", " def test_rotation(self):\n", " assert_equal(is_rotation('o', 'oo'), False)\n", " assert_equal(is_rotation(None, 'foo'), False)\n", @@ -140,10 +140,12 @@ " assert_equal(is_rotation('foobarbaz', 'barbazfoo'), True)\n", " print('Success: test_rotation')\n", "\n", + "\n", "def main():\n", " test = TestRotation()\n", " test.test_rotation()\n", "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/arrays_strings/rotation/test_rotation.py b/arrays_strings/rotation/test_rotation.py index 9daf22f..4c14422 100644 --- a/arrays_strings/rotation/test_rotation.py +++ b/arrays_strings/rotation/test_rotation.py @@ -2,7 +2,7 @@ from nose.tools import assert_equal class TestRotation(object): - + def test_rotation(self): assert_equal(is_rotation('o', 'oo'), False) assert_equal(is_rotation(None, 'foo'), False) @@ -11,9 +11,11 @@ class TestRotation(object): assert_equal(is_rotation('foobarbaz', 'barbazfoo'), True) print('Success: test_rotation') + def main(): test = TestRotation() test.test_rotation() + if __name__ == '__main__': main() \ No newline at end of file diff --git a/arrays_strings/unique_chars/test_unique_chars.py b/arrays_strings/unique_chars/test_unique_chars.py index 50ff05c..5dd6016 100644 --- a/arrays_strings/unique_chars/test_unique_chars.py +++ b/arrays_strings/unique_chars/test_unique_chars.py @@ -3,12 +3,13 @@ from nose.tools import assert_equal class TestUniqueChars(object): - def test_unique_chars(self, func): + def test_unique_chars(self, func): assert_equal(func(''), True) assert_equal(func('foo'), False) assert_equal(func('bar'), True) print('Success: test_unique_chars') + def main(): test = TestUniqueChars() test.test_unique_chars(unique_chars) @@ -19,6 +20,7 @@ def main(): # Alternate solutions are only defined # in the solutions file pass - + + if __name__ == '__main__': main() \ No newline at end of file diff --git a/arrays_strings/unique_chars/unique_chars_challenge.ipynb b/arrays_strings/unique_chars/unique_chars_challenge.ipynb index 0e85a04..91ea17c 100644 --- a/arrays_strings/unique_chars/unique_chars_challenge.ipynb +++ b/arrays_strings/unique_chars/unique_chars_challenge.ipynb @@ -34,7 +34,6 @@ "source": [ "## Constraints\n", "\n", - "* Can you assume the string is ASCII?\n", " * Yes\n", " * Note: Unicode strings could require special handling depending on your language\n", @@ -112,12 +111,13 @@ "\n", "class TestUniqueChars(object):\n", "\n", - " def test_unique_chars(self, func):\n", + " def test_unique_chars(self, func):\n", " assert_equal(func(''), True)\n", " assert_equal(func('foo'), False)\n", " assert_equal(func('bar'), True)\n", " print('Success: test_unique_chars')\n", "\n", + "\n", "def main():\n", " test = TestUniqueChars()\n", " test.test_unique_chars(unique_chars)\n", @@ -128,7 +128,8 @@ " # Alternate solutions are only defined\n", " # in the solutions file\n", " pass\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] diff --git a/arrays_strings/unique_chars/unique_chars_solution.ipynb b/arrays_strings/unique_chars/unique_chars_solution.ipynb index d07e0a2..4c0c787 100644 --- a/arrays_strings/unique_chars/unique_chars_solution.ipynb +++ b/arrays_strings/unique_chars/unique_chars_solution.ipynb @@ -213,12 +213,13 @@ "\n", "class TestUniqueChars(object):\n", "\n", - " def test_unique_chars(self, func):\n", + " def test_unique_chars(self, func):\n", " assert_equal(func(''), True)\n", " assert_equal(func('foo'), False)\n", " assert_equal(func('bar'), True)\n", " print('Success: test_unique_chars')\n", "\n", + "\n", "def main():\n", " test = TestUniqueChars()\n", " test.test_unique_chars(unique_chars)\n", @@ -229,7 +230,8 @@ " # Alternate solutions are only defined\n", " # in the solutions file\n", " pass\n", - " \n", + "\n", + "\n", "if __name__ == '__main__':\n", " main()" ] @@ -258,21 +260,21 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 2", "language": "python", - "name": "python3" + "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", - "version": 3 + "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.4.3" + "pygments_lexer": "ipython2", + "version": "2.7.10" } }, "nbformat": 4,