I have an array like :
a=np.array([2,7])
a=[2,7]
and I want to swap the same array like 7,2 is there anyway to do?
answer should be like 7,2
a=[7,2]
I have an array like :
a=np.array([2,7])
a=[2,7]
and I want to swap the same array like 7,2 is there anyway to do?
answer should be like 7,2
a=[7,2]
#a=np.array([2,7])
a=[2,7]
# Reversing a list using slice notation
print (a[::-1]) # [7, 2]
# The reversed() method
print (list(reversed(a))) # [7, 2]
swap two elements in a list:
# Swap function
def swapPositions(list, pos1, pos2):
list[pos1], list[pos2] = list[pos2], list[pos1]
return list
a=[2,7]
pos1, pos2 = 0, 1
print(swapPositions(a, pos1 - 1, pos2 - 1))