All problems
Reshape Flat List to Image
Problem
Reshape a flat list into a rows x cols 2D image in row-major order.
You may assume len(flat) equals rows * cols. A rows value of 0 returns [].
Hint
Slice the flat list into consecutive chunks of length cols.
Test cases
case 1
in: [[1,2,3,4,5,6],2,3]
expected: [[1,2,3],[4,5,6]]
case 2
in: [[7],1,1]
expected: [[7]]
case 3
in: [[],0,3]
expected: []
case 4
in: [[1,2,3,4,5,6],3,2]
expected: [[1,2],[3,4],[5,6]]
Starter codePython
def reshape_to_image(flat, rows, cols):
# Your code here
pass4 test cases · run your code against them in the editor