what would be the best way of swapping indices of list of undetermined length? I want to swap the positions of the numbers in pairs, so that the first and second numbers are swapped, the third and fourth numbers are swapped, etc. The only way I know how to do it is as such:
my_list[0], my_list[1] = my_list[1], my_list[0]
But I have no clue how to do so if the list is of undetermined length. A sample list would include [1,2,3,4] and would return [2,1,4,3]. But if it's odd, the last index of the list stays in the same position.