tuple unpacking

As we’ve already seen, tuples are very useful when unpacking them into several variables:
person = ('Mary', 20, 180)
name, age, height = person
print(name)    # Mary
print(age)     # 20
print(height)  # 180
This is very useful when swapping the values of variables:
n1 = 'Anna'
n2 = 'Mary'
n1, n2 = n2, n1
print(n1)   # Mary
print(n2)   # Anna

Challenge

Given a list of n numbers, you are asked to perform o operations on those. Each operation represents a swapping of two numbers. Given 2 indices, the values situated at those locations need to be replaced by one another. You are asked to print the resulting list at the end.
The first line of the input contains two integers n and o - the number of elements in the list and the number of operations you need to perform. The next line contains n integers separated by a space. The next o lines contain two integers on each line separated by a space - the indices which need to be swapped.
The program should print the resulting list of numbers separated by a space.
Input
Output
5 2 5 6 7 8 9 0 2 1 3
7 8 5 6 9
Explanation:
  1. Initially - 5 6 7 8 9
  1. After the first operation - 7 6 5 8 9
  1. After the second one - 7 8 5 6 9
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue