LESSON 65 / 75·2 min readFoundation

Linked list in Python

Should knowConcept lesson
01 Understand02 Recall03 Prepare

Node structure

Python
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

Problems to practice

  • Reverse Linked List
  • Middle of the Linked List
  • Remove Nth Node from End
  • Merge Two Sorted Lists
  • Detect Cycle
  • Intersection of Two Linked Lists

Example: reverse linked list

Python
def reverse_list(head):
    prev = None
    curr = head

    while curr:
        nxt = curr.next
        curr.next = prev
        prev = curr
        curr = nxt

    return prev

PAUSE & RECALL

Can you explain it without the notes?

Linked list in Python

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Node structure

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Stack and queue in Python

Adapted from 18_DSA_PYTHON.md · “4. Linked list in Python”. Examples are study fragments; framework behavior can depend on your version.