Question
ANSWER THE FOLLOWING QUESTION IN PYTHON AND PUT THE ANSWER IN THE ORGINAL QUESTION WHERE IT IS SUPPOSED TO BE ! 1. import unittest #
ANSWER THE FOLLOWING QUESTION IN PYTHON AND PUT THE ANSWER IN THE ORGINAL QUESTION WHERE IT IS SUPPOSED TO BE !
1.
import unittest
# --------------------------------------------------------------
# Column Sort
# --------------------------------------------------------------
'''
Given a matrix A, return a list of column indices in ascending order of highest column sums.
Assume no ties.
ex:
A = [
[1,2,3,4,5],
[7,4,3,2,-7],
[4,1,1,3,2],
[1,0,3,0,0],
[0,-1,9,3,1]]
Column sums:
Column 0 -> 13
Column 1 -> 6
Column 2 -> 19
Column 3 -> 12
Column 4 -> 1
So ordering these column indices by ascending highest sum, we return
[4,1,3,0,2].
'''
def col_sort(A) :
### CODE BELOW ###
### CODE ABOVE ###
pass
# --------------------------------------------------------------
# The Testing
# --------------------------------------------------------------
class myTests(unittest.TestCase):
def test1(self):
self.assertEqual(col_sort([
[1,2,3,4,5],
[7,4,3,2,-7],
[4,1,1,3,2],
[1,0,3,0,0],
[0,-1,9,3,1]]
), [4,1,3,0,2])
def test2(self):
self.assertEqual(col_sort( [
[1,2,3,4,5,6,7,8,9],
[1,2,3,4,5,6,7,8,9],
[1,2,3,4,5,6,7,8,9],
[1,2,3,4,5,6,7,8,9],
[1,2,3,4,5,6,7,8,9],
[1,2,3,4,5,6,7,8,9],
[1,2,3,4,5,6,7,8,9]]
), [0,1,2,3,4,5,6,7,8])
def test3(self):
self.assertEqual(col_sort([
[1,2,3,4,5,6,7,8,9],
[6,7,2,3,1,6,8,-2,-1],
[6,1,2,3,9,4,2,4,1],
[1,1,1,1,1,1,1,1,1],
[1,1,1,1,1,1,1,1,1]]
), [2,8,1,3,7,0,4,5,6])
def test4(self):
self.assertEqual(col_sort([
[1,2,3,4,5,6,7,8,9]]
), [0,1,2,3,4,5,6,7,8])
def test5(self):
self.assertEqual(col_sort([
[0,1],
[3,1]]
), [1,0])
def test6(self):
self.assertEqual(col_sort([
[-1]]
), [0])
if __name__ == '__main__':
unittest.main(exit=True)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started