Python program to interchange first and last elements in a list.
Python program to interchange first and last elements in a list
Code -
--------------------
al = ['First element', 'b', 'c', 'd', 'Just', 'Last element']
def reverse_do():
print(al)
a = (len(al))
b = a - 1
c = al[b]
d = al[0]
al.pop()
al.remove(d)
al.append(d)
al.insert(0, c)
print(al)
reverse_do()
Comments
Post a Comment