← Data Structures
9 / 25
Lesson 9 — Linked list
Linked list: nodes holding hands
A linked list is a chain of nodes. Each node holds a value and a reference (a "pointer") to the next node; the last node's next is None. You keep only the first node, the head. To visit every value you traverse: start at the head and follow next until you hit None.
cur = first
while cur:
print(cur.value)
cur = cur.next
Why it matters: adding or removing at the front is instant (no shifting like in a list), and linked structures are the basis of trees and graphs.
Want it another way?
Task
Inside the loop, collect node.value into values and move to node.next. Expected: 1 -> 2 -> 3.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
Test your knowledge
A quick 3-question quiz on this lesson — instant feedback.