pad_tuple(values, length, fill=0) that returns a tuple of exactly length elements: values followed by enough copies of fill to reach length, built purely with tuple concatenation (+) and repetition (*). If values already has length or more elements, return only its first length elements (via slicing).pad_tuple((1, 2), 5)
(1, 2, 0, 0, 0)
(1, 2) concatenated with (0,) * 3.
pad_tuple((1, 2, 3), 2)
(1, 2)
Already long enough, so it is trimmed to length 2.
(fill,) * n repeats the fill value n times as a tuple.
values + (fill,) * (length - len(values)) concatenates the two.