easy +10 pts

Pad Array Edges

Create a new list with zeros added to the beginning and end.

Write a function `pad_array(lst, left, right)` that returns a new list which is the original list with `left` zeros prepended and `right` zeros appended. The original list must remain unchanged. For example, `pad_array([1, 2], 1, 2)` should return `[0, 1, 2, 0, 0]`. **Signature:** `def pad_array(lst, left, right):` - `lst`: a list of integers. - `left`: a non-negative integer, the number of zeros to add at the beginning. - `right`: a non-negative integer, the number of zeros to add at the end. Return a new list, never modify the input.

Constraints

0 <= left, right <= 1000 0 <= len(lst) <= 1000 Return a new list; the input list must not be mutated.

Example

>>> pad_array([1, 2], 1, 2)
[0, 1, 2, 0, 0]
>>> pad_array([], 2, 3)
[0, 0, 0, 0, 0]
>>> pad_array([5], 0, 0)
[5]
10 points ~10 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

You can create padding lists using `[0] * n`.
Combine padding and the original list using `+`.
Make sure to return a new list and not modify the original.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.