Gadgets 4 Students Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
0 like 0 dislike
in Data Structures and Algorithms by Goeduhub's Expert (2.2k points)

Deletion from beginning in singly linked list 

Where can I do online courses From Word's Top Instructors?

UDEMY::  Attend All Udemy Courses in Just INR 450[Coupon]
Coursera:: Join For FREE

1 Answer

0 like 0 dislike
by Goeduhub's Expert (2.2k points)
edited by
Best answer

Python program for deletion of node from beginning in singly linked list

 To delete a node at beginning from linked list,we need to do following steps:

Step:1 Find previous node of the node to be deleted.

Step:2 Changed next of previous node.

Step:3 Free memory for the node to be deleted.

first node deletion in linked list

# Node class 

class Node:

    # Function to initialize the node object 

    def __init__(selfdata=Nonenext=None): = data # Assign data = next # Initialize next as null 

# Linked List class 

class LinkedList:

    # Function to initialize the LinkedList object 

    def __init__(self):

        self.head = None

    # print function prints contents of linked list starting from head

    def print(self):

        # if linked list is empty

        if self.head is None:

            print("Linked list is empty")


        itr = self.head

        #taking empty string and appending values

        llstr = ''

        while itr:

            llstr += str(' --> '

            itr =


    # Function to insert a new node at the beginning

    def insert_at_begining(selfdata):

        node = Node(data, self.head)

        self.head = node


    #remove first element of the singly linkedlist

    def remove_first(self):

      # if linked list is empty

      if self.head is None:

        print("Empty,nothing to remove"

        return None


      self.head =

# Code execution starts here     

if __name__ == '__main__':

    ll = LinkedList()







    print ("Created Linked List: ")


    print ("Print Linked List after deletion at first position: ")




Created Linked List:

Yellow --> Black --> Green --> Red --> Print Linked List after deletion at first position:  

Black --> Green --> Red -->  

Code your future with Programming skills. Courses starting at ₹ 455 only!

3.3k questions

7.1k answers


4.5k users

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs


About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © Social::   |  | 


Free Online Directory