PPA-9
Question
Implement the following functions:
- Write a function named
get_columnthat accepts a matrix namedmatand a non-negative integer namedcolas arguments. It should return the column that is at indexcolin the matrixmatas a list. Zero-based indexing is used here. - Write a function named
get_rowthat accepts a matrix namedmatand a non-negative integer namedrowas arguments. It should return the row that is at indexrowin the matrixmatas a list. Zero-based indexing is used here.
You do not have to accept input from the user or print output to the console. You just have to write the definition of both the functions.
Hint
Such functions are extremely useful. They play the role of helper functions. When a problem is broken down into smaller parts, these helper functions will come in handy while solving the sub-problems. You should make it a point to practice writing these functions as many times as possible.
To extract a row, iterate through the columns of the matrix. Fix the row index, the first index of the matrix, and vary the column index, the second index, from \(0\) to the \(n - 1\), where there are \(n\) columns in the matrix. A similar operation is required for extracting a column of the matrix.