xxxxxxxxxx
x=int(input("Enter x:"))
y=int(input("Enter y:"))
# Method 1
x,y=y,x
print(x,y)
# Method 2
t=x
x=y
y=t
print(x,y)
# Method 3
x=x+y
y=x-y
x=x-y
print(x,y)
# Method 4
x=x^y
y=x^y
x=x^y
print(x,y)
# Method 5
x=x*y
y=x/y
x=x/y
print(x,y)
xxxxxxxxxx
# suppose the list is x:
return [x[i:i+2] for i in range(0, len(x), 2)]
# or, as a generator
return x[i:i+2]for i in range(0,len(x),2)
xxxxxxxxxx
in python below is how you swap 2 elements of list
x[i+1],x[i]=x[i],x[i+1]
Don't use function swap(user defined or pre-defined)
xxxxxxxxxx
def swapPositions(list, pos1, pos2):
list[pos1], list[pos2]=list[pos2], list[1]
return list
List=[1,3,5,7,9,11]
pos1, pos2=1,3
print(swapPositions(list, pos1-1, pos2-1))