Header Ads

Python program to interchange first and last elements in a list

Question Source

Code :

# This function is used to swap the first and last element of the list
def SwapList(list):
ln = len(list)
buf = list[0]
list[0] = list[ln-1]
list[ln-1] = buf
return list


l = [13, 36, 10, 57, 25]
print(SwapList(l))

Output :

[25, 36, 10, 57, 13]

Post a Comment

0 Comments