If I have a list like [1, 2, 3, 4, 5]
what's considered a more pythonic way (if this is not already it) to repeat the first and last elements only and obtain [1, 1, 2, 3, 4, 5, 5]
?
What I'm doing right now is:
a = [1, 2, 3, 4, 5]
b = [a[0], *a, a[-1]]
I would do the following, which simply glues together three separate lists: