classNode:# Constructor to initialize the node objectdef__init__(self,data):self.data=dataself.next=NoneclassLinkedList:# Function to initialize headdef__init__(self):self.head=NonedefreverseUtil(self,curr,prev):# If last node mark it headifcurr.nextisNone:self.head=curr# Update next to prev nodecurr.next=prevreturn# Save curr.next node for recursive callnext=curr.next# And update nextcurr.next=prevself.reverseUtil(next,curr)# This function mainly calls reverseUtil()# with previous as Nonedefreverse(self):ifself.headisNone:returnself.reverseUtil(self.head,None)# Function to insert a new node at the beginningdefpush(self,new_data):new_node=Node(new_data)new_node.next=self.headself.head=new_node# Utility function to print the LinkedListdefprintList(self):temp=self.headwhile(temp):print(temp.data,end=" ")temp=temp.next# Driver programllist=LinkedList()llist.push(8)llist.push(7)llist.push(6)llist.push(5)llist.push(4)llist.push(3)llist.push(2)llist.push(1)print("Given linked list")llist.printList()llist.reverse()print("\nReverse linked list")llist.printList()