Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a couple of Python functions that deal with two-dimensional lists. reverse_transpose , which takes a two-dimensional matrix of objects it doesn't matter what kind

write a couple of Python functions that deal with two-dimensional lists.

  • reverse_transpose, which takes a two-dimensional matrix of objects it doesn't matter what kind of objects they are, but you can assume that the matrix is rectangular and that there's at least one row and at least one column and returns a new two-dimensional matrix that is the reverse transpose of the given one. So, what's the reverse transpose? It requires two kinds of changes:
    • By "transpose," I mean that the resulting list uses columns where the original list uses rows, and uses rows where the original list uses columns. So, for example, if the original list had a row containing the values 1, 2, and 3, the new list would have a column containing the values 1, 2, and 3.
    • By "reverse," I mean that the first row in the original list would become the last column in the new list, that the first column in the original list would become the last row in the new list, and so on.
  • calculate_sums, which takes a two-dimensional list of numbers and modifies it, so that, for each cell a[i][j], it contains the sum of the values of all cells a[m][n] that were originally in the list, where m i and n j.

Here's one quick example of each function in action:

>>> a = [['x', 'y', 'z'], ['w', 'v', 't'], ['p', 'r', 's']] >>> b = reverse_transpose(a) >>> a [['x', 'y', 'z'], ['w', 'v', 't'], ['p', 'r', 's']] >>> b [['s', 't', 'z'], ['r', 'v', 'y'], ['p', 'w', 'x']] >>> c = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] >>> calculate_sums(c) >>> c [[45, 33, 18], [39, 28, 15], [24, 17, 9]] 

Docstrings are not necessary, since we've already agreed on what problems are being solved here.

Testing your functions

As usual, you'll need to write automated tests, but since we've learned some new techniques for that this week, let's put them to use. Using the unittest module from Python's standard library, write a unit test class for each of your functions with the proper assert functions to test. No specific requirement with regard to how many tests you write as the goal when writing tests is a qualitative, rather than quantitative, one you'll want to be sure that you've separated different kinds of test cases into separate methods in your unit test classes, and that you've thought carefully about what tests would be interesting to include, rather than just writing as many tests as you can without considering whether they're meaningfully different from one another

example of tests would be

from problem3 import Student, Club import random import unittest class StudentTest(unittest.TestCase): def test_has_id_given_when_created(self): student1 = Student(234567) student2 = Student(456789) self.assertEqual(student1.student_id(), 234567) self.assertEqual(student2.student_id(), 456789) class ClubTest(unittest.TestCase): def setUp(self): self._club = Club() self._student_ids = list(range(10000, 19999)) random.shuffle(self._student_ids) def test_new_clubs_have_no_students(

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Upgrading Oracle Databases Oracle Database New Features

Authors: Charles Kim, Gary Gordhamer, Sean Scott

1st Edition

B0BL12WFP6, 979-8359657501

More Books

Students also viewed these Databases questions

Question

=+What is the nature of their impact?

Answered: 1 week ago

Question

Explain the function and purpose of the Job Level Table.

Answered: 1 week ago