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

Popular posts from this blog

Single Inheritance, multiple inheritance and multilevel inheritance in python.

Git Commands.

Using class objects, Instance variables, and class variables, class methods and static method in python