Originally published on CodingCush .
A linked list is a chain of boxes called nodes, where each node holds one piece of data and a link to the next node. The first node is called the head, and the chain ends when a node links to nothing. Unlike an array, it does not store items side by side, so it can grow or shrink one node at a time without moving the rest. Below, you will build one in Python and learn when to pick it over an array. Every example was run with Python 3.12.3, so the outputs shown are real.
What Is a Linked List?
A linked list stores items in order, but not in one neat block. Each item lives in its own node, and each node points to the next one, like a treasure hunt where every clue tells you where the next clue is hidden. To read the list, start at the head and follow the links until you reach a node whose link is empty. That empty link, written as None in Python, marks the end of the list.…