All problems
Pad Sequences to Batch Maximum
Problem
Pad every sequence on the right with pad_value until it matches the longest sequence in the batch, and return the padded batch.
Preserve element order and return an empty list for an empty batch.
Hint
Find the maximum length first, then append the difference of pad values.
Test cases
case 1
in: [[[1,2],[3]],0]
expected: [[1,2],[3,0]]
case 2
in: [[[1],[2]],9]
expected: [[1],[2]]
case 3
in: [[[],[1,2,3]],0]
expected: [[0,0,0],[1,2,3]]
case 4
in: [[],0]
expected: []
Starter codePython
def pad_to_batch_max(sequences, pad_value=0):
# Your code here
pass4 test cases · run your code against them in the editor