An Introduction to Linked Lists in Python

Aditi Deodhar
2 min readFeb 10, 2021

A linked list is a data structure used for storing a sequence of elements. It’s data with some structure (the sequence).

Implementation of Linked List

class LinkedList():
def __init__(self):
self.head = None

def append(self, value):
if self.head is None:
self.head = Node(value)
current_node = self.head
while is not None:
current_node = = Node(value)

def show_elements(self):
current = self.head
while current is not None:
current =

def length(self):
result = 0
current = self.head
while current is not None:
result += 1
current =
return result

def get_element(self, position):
i = 0
current = self.head
while current is not None:
if i == position:
current =
i += 1
return None

How to reverse a Linked List?

def reverse(l):
if l.head is None:

current_node = l.head
prev_node = None

while current_node is not None:
# Track the next node
next_node =

# Modify the current node = prev_node

# Update prev and current
prev_node = current_node
current_node = next_node

l.head = prev_node

Real World Applications of Linked Lists

  1. Image viewer — Previous and next images are linked, hence can be accessed by next and previous button.
  2. Previous and next page in web browser — We can access previous and next url searched in web browser by pressing back and next button since, they are linked as linked list.
  3. Music Player — Songs in music player are linked to previous and next song. you can play songs either from starting or ending of the list.



Aditi Deodhar

MSIS @ Northeastern University | Data Science Enthusiast