This notebook was prepared by Donne Martin. Source and license info is on GitHub.
str0 = 'ABCDEFGHIJ' str1 = 'FOOBCDBCDE'
result: 'BCDE'
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 StringCompare(object):
def longest_common_subseq(self, str0, str1):
# TODO: Implement me
pass
The following unit test is expected to fail until you solve the challenge.
# %load test_longest_common_subseq.py
import unittest
class TestLongestCommonSubseq(unittest.TestCase):
def test_longest_common_subseq(self):
str_comp = StringCompare()
self.assertRaises(TypeError, str_comp.longest_common_subseq, None, None)
self.assertEqual(str_comp.longest_common_subseq('', ''), '')
str0 = 'ABCDEFGHIJ'
str1 = 'FOOBCDBCDE'
expected = 'BCDE'
self.assertEqual(str_comp.longest_common_subseq(str0, str1), expected)
print('Success: test_longest_common_subseq')
def main():
test = TestLongestCommonSubseq()
test.test_longest_common_subseq()
if __name__ == '__main__':
main()
Review the Solution Notebook for a discussion on algorithms and code solutions.