Delete Node in a Linked List in Python
PythonServer Side ProgrammingProgramming
Suppose we have a linked list with few elements. Our task is to write a function that will delete the given node from the list. So if the list is like 1 → 3 → 5 → 7 → 9, and after deleting 3, it will be 1 → 5 → 7 → 9.
Consider we have the pointer ‘node’ to point that node to be deleted, we have to perform these operations to delete the node −
- node.val = node.next.val
- node.next = node.next.next
Prerequisites
To learn about singly linked lists, you should know:
- Python 3
- OOP concepts
- Singly linked list - inserting a node and printing the nodes