How to Convert singly linked list into circular linked list in Python

In this tutorial, we shall convert a singly linked list into circular linked list in Python. A Linked List is a linear data structure where the elements are linked using pointers. A circular Linked List is obtained from a singly linked list as follows.


  1. Enter Elements into an empty linked list using the push function.
  2. To convert a linked list into a circular linked list, traverse through the linked list to find the last node.
  3. Last Node is the node that has NULL as its next node.
  4. Make the last node point to the starting node (
  5. Display the circular linked list.

Python program to convert the singly linked list into circular linked list

Below is our Python code:

class Node: 
  def __init__(self,data): = data = None

def push(head, data): 
  if not head: 
    return Node(data) 

  # Assign the data into newNode. 
  newNode = Node(data) = head 
  head = newNode 
  return head 
def circular(head): 
  start = head  
  while( is not None): 
    head = #to reach end of the list = start #Link the end of linked list to start
  return start 
def displayList(node): 
  start = node 
  while( is not start): 
    print("{} ".format(,end="")

  # Display the last node of circular linked list. 
  print("{} ".format(,end="") 

# Driver Code 
if __name__=='__main__': 
  # Start with empty list 
  head = None

  # Linked List 12 23 34 41 69 
  head = push(head, 69) 
  head = push(head, 41) 
  head = push(head, 34) 
  head = push(head, 23) 
  head = push(head, 12) 

  print("Display List:") 

After running the above program we can see the output result:

Display List:
12 23 34 41 69

Also Read Related topics to Linked Lists:

Thank You for reading and Keep Learning ๐Ÿ™‚

Leave a Reply