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 SortedMatrix(object):
def find_val(self, matrix, val):
# TODO: Implement me
pass
The following unit test is expected to fail until you solve the challenge.
# %load test_search_sorted_matrix.py
import unittest
class TestSortedMatrix(unittest.TestCase):
def test_find_val(self):
matrix = [[20, 40, 63, 80],
[30, 50, 80, 90],
[40, 60, 110, 110],
[50, 65, 105, 150]]
sorted_matrix = SortedMatrix()
self.assertRaises(TypeError, sorted_matrix.find_val, None, None)
self.assertEqual(sorted_matrix.find_val(matrix, 1000), None)
self.assertEqual(sorted_matrix.find_val(matrix, 60), (2, 1))
print('Success: test_find_val')
def main():
test = TestSortedMatrix()
test.test_find_val()
if __name__ == '__main__':
main()
Review the Solution Notebook for a discussion on algorithms and code solutions.