PPA-9
Question
Implement the following functions:
- Write a function named
get_column
that accepts a matrix namedmat
and a non-negative integer namedcol
as arguments. It should return the column that is at indexcol
in the matrixmat
as a list. Zero-based indexing is used here. - Write a function named
get_row
that accepts a matrix namedmat
and a non-negative integer namedrow
as arguments. It should return the row that is at indexrow
in the matrixmat
as 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.