def trp(l, n):
    return l[:n] + [0] * (n - len(l))
trp([], 4)
[0, 0, 0, 0]
trp([1, 2, 3, 4], 4)
[1, 2, 3, 4]
trp([1, 2, 3, 4, 5], 4)
[1, 2, 3, 4]
trp([1, 2, 3], 4)
[1, 2, 3, 0]
Padding or truncating a Python list