This notebook was prepared by Donne Martin. Source and license info is on GitHub.
Refer to the Solution Notebook. If you are stuck and need a hint, the solution notebook's algorithm discussion might be a good place to start.
class Solution(object):
def match_note_to_magazine(self, ransom_note, magazine):
# TODO: Implement me
pass
The following unit test is expected to fail until you solve the challenge.
# %load test_ransom_note.py
import unittest
class TestRansomNote(unittest.TestCase):
def test_ransom_note(self):
solution = Solution()
self.assertRaises(TypeError, solution.match_note_to_magazine, None, None)
self.assertEqual(solution.match_note_to_magazine('', ''), True)
self.assertEqual(solution.match_note_to_magazine('a', 'b'), False)
self.assertEqual(solution.match_note_to_magazine('aa', 'ab'), False)
self.assertEqual(solution.match_note_to_magazine('aa', 'aab'), True)
print('Success: test_ransom_note')
def main():
test = TestRansomNote()
test.test_ransom_note()
if __name__ == '__main__':
main()
Review the Solution Notebook for a discussion on algorithms and code solutions.