Swap Stack Pairs

The stack is given as a list: the bottom is on the left, and the top is on the right. Given stack, go through its elements from bottom to top in pairs. Swap the two elements in each pair. If there is an odd number of elements, leave the final top element unchanged.

Примеры

Ввод
[3, 8, 17, 9, 1, 10]
Вывод
[8, 3, 9, 17, 10, 1]
Ввод
[3, 8, 17, 9, 1]
Вывод
[8, 3, 9, 17, 1]
Ввод
[]
Вывод
[]

Нужно реализовать

def switch_pairs(stack: list[int]) -> list[int]:

Теги

stack
PostgreSQLv16
Entre para enviar

O resultado da execução do código aparecerá aqui

Visible tests
1
Input
[3,8,17,9,1,10]
Expected[8,3,9,17,10,1]
2
Input
[3,8,17,9,1]
Expected[8,3,9,17,1]
3
Input
[]
Expected[]
4
Input
[1,2]
Expected[2,1]
5
Input
[10,1,9,17,8,3]
Expected[1,10,17,9,3,8]
6
Input
[1,2,3]
Expected[2,1,3]
Focus radio
Paused · SomaFM · Fluid