In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of November 23rd
(this exercise will still be available for submission after that deadline, but without counting towards your grade)
[to understand the context of this problem, you should read the class #06 exercise sheet]
In this problem you should submit a function as described. Inside the function do not print anything that was not asked!
After Patty successfully transformed the messy matrix into a simple list, her sister Selma, equally cynical but always looking for a new challenge, decides she wants to put a spin on the project. Selma had been hearing about the various ways people organize data, and she thought it would be fun to take Patty's newly flattened list and turn it back into a matrix. After all, what’s the point of making things easy if you can’t complicate them a little?
Write a function list_to_matrix(lst, r, c) that given a list lst with r * c elements, returns a matrix with r rows and c columns given as a list of lists where the elements come from the list: the first row corresponds to the first c elements of the list, the second row to the next c elements, and so on.
The following limits are guaranteed in all the test cases that will be given to your program:
1 ≤ |lst| ≤ 10 000 | Size of the list | |
1 ≤ r, c ≤ 100 | Number of rows and columns |
Example Function Calls | Example Output |
print(list_to_matrix([1,2,3,4,5,6,7,8,9], 3, 3)) print(list_to_matrix([9,8,7,6,5,4,3,2,1,0], 2, 5)) |
[[1, 2, 3], [4, 5, 6], [7, 8, 9]] [[9, 8, 7, 6, 5], [4, 3, 2, 1, 0]] |