What is the best way to pad a Python list
to a specific length by repeating the start element at the start and end element at the end?
For example, I have the following list of 5 elements:
['a', 'b', 'c', 'd', 'e']
and I want to edge pad both sides of it so it has a new length of 10, producing
# either
['a', 'a', 'a', 'b', 'c', 'd', 'e', 'e', 'e', 'e']
# or
['a', 'a', 'a', 'a', 'b', 'c', 'd', 'e', 'e', 'e']
(When the target length minus the current length is an odd number, as in the example above, I don't mind which of the start and end elements is repeated once more than the other in order to correctly pad the list to the target length.)
There are several other related questions on SO (here, here and here, for example), but all of these concern zero padding (or similar) only one side. I am specifically asking about edge padding both sides.