swap_first_last(items) that takes a list items and returns a new list with the first and last elements swapped, using Python's multiple-assignment/unpacking syntax (no manual temp-variable juggling of indices).swap_first_last([1, 2, 3, 4])
[4, 2, 3, 1]
First (1) and last (4) traded places.
swap_first_last([7])
[7]
Single element: swapping with itself changes nothing.
Copy the list first, e.g. with items[:] or list(items).
result[0], result[-1] = result[-1], result[0] does a tuple-unpack swap.