Write a function unflatten(items, n_rows) that takes a flat list and turns it into a
matrix (a list of lists) with n_rows rows. The elements are filled in row by row, so
each row holds len(items) // n_rows consecutive elements. You may assume n_rows is at
least 1 and divides len(items) exactly. Use a comprehension rather than an explicit
loop.
Example
unflatten([1, 2, 3, 4, 5, 6], 2) -> [[1, 2, 3], [4, 5, 6]]
unflatten([1, 2, 3, 4], 4) -> [[1], [2], [3], [4]]
Implement this function:
def unflatten(items: list, n_rows: int) -> list:
Write the function only — the arguments are read for you and the return value is printed automatically.
Arguments arrive as one Python literal per line, in this order: items, n_rows.
Input
[1, 2, 3, 4, 5, 6]
2
Output
[[1, 2, 3], [4, 5, 6]]