Overview
Python lists are ordered, mutable, dynamically sized containers supporting any type.
Analogy
A shopping list that can grow or shrink; you can add, remove, or reorder items freely.
Step-by-step
- Create: lst = [1, 2, 3] or lst = list(range(5)).
- Access: lst[0] for first, lst[-1] for last.
- Append: lst.append(x); insert: lst.insert(i, x).
- Remove: lst.remove(x) by value; del lst[i] by index; lst.pop(i) by index (returns item).
Visual
lst=[1,2,3]; lst.append(4) → [1,2,3,4]; del lst[0] → [2,3,4]
Common mistakes
- IndexError when accessing out of range.
- list.remove() raises ValueError if element not found.
Practice questions
- Build a stack using a list (append/pop).
- Find all duplicates in a list.
Time
append O(1) amortized, insert/remove O(n)