Question: def transform(data, num_rows, num_cols): Description: o Given a one-dimensional list of information data, return a new two-dimensional matrix of information where num_rows is the number
def transform(data, num_rows, num_cols): Description: o Given a one-dimensional list of information data, return a new two-dimensional matrix of information where num_rows is the number of rows in this matrix, and num_cols is the number of columns in this matrix. Assumptions: o The elements of data could be any basic type (float, int, bool, etc.) o If the desired matrix size is smaller than the number of elements in data, return an empty list. o If the size of the desired matrix is larger than the number of elements in data, fill in the gap with zeroes. Restrictions: o Remember, do not modify the original list. Examples: o # input and output sizes match transform([1,2,3,4,5,6], 2, 3) [[1,2,3],[4,5,6]] o # input and output sizes don't match (too big) transform([1,2,3,4,5,6], 3, 3) [[1,2,3],[4,5,6],[0,0,0]] o # input and output sizes don't match (too small) transform([1,2,3,4,5,6], 2, 2) []
def transform(data, num_rows, num_cols): Description: o Given a one-dimensional list of information data, return a new two-dimensional matrix of information where num_rows is the number of rows in this matrix, and num_cols is the number of columns in this matrix. Assumptions: o The elements of data could be any basic type (float, int, bool, etc.) o If the desired matrix size is smaller than the number of elements in data, return an empty list. If the size of the desired matrix is larger than the number of elements in data, fill in the gap with zeroes. Restrictions: o Remember, do not modify the original list. Examples: o # input and output sizes match transform([1,2,3,4,5,6], 2, 3) [[1,2,3], [4,5,6]] O # input and output sizes don't match (too big) transform((1,2,3,4,5,6], 3, 3) [[1,2,3], [4,5,6], [0,0,0]] # input and output sizes don't match (too small) transform([1,2,3,4,5,6], 2, 2) 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
