How To Reverse A Linked List — Explained Visually Using Python

Liu Zuo Lin
CodeX
Published in
4 min readJan 29, 2022

--

I actually took quite a while to understand how to do this a couple of years back, and hope to explain this as clearly as possible. If you’re completely new to linked lists, I’ve previously written a short article explaining essentially what they are and how to code them here:

However, these are simply the basics, and chances are that interviewers in coding interviews will ask us more complicated stuff like reversing a linked list, combining 2 linked lists, etc.

Quickly Creating Our Linked List

Defining our Node class

class Node:
def __init__(self, value):
self.value = value
self.next = None

Creating our linked list

root = Node("A")
current = root
for letter in "BCDE":
current.next = Node(letter)
current = current.next

A visual representation of our linked list

--

--