Lesson 16 of 19 · 2 min
Comparison Table — All Four Data Structures
| Feature | List [] | Tuple () | Dictionary {k:v} | Set {v} |
|---|---|---|---|---|
| Ordered? | Yes | Yes | Yes (Python 3.7+) | No — random order |
| Mutable? | Yes | No — fixed forever | Yes | Yes |
| Allows Duplicates? | Yes | Yes | Keys unique; values can repeat | No — duplicates auto-removed |
| Indexable? | Yes — by position (0, 1, 2…) | Yes — by position | Yes — by key | No — cannot use [0] |
| Best Use Case | Shopping cart, student roster, results | GPS coords, RGB colour, database row | Profile, config, word count | Unique emails, tags, set math |
| How to Create Empty | [] | () | {} | set() ← NOT {}! |
| Speed (lookup) | O(n) slow scan | O(n) slow scan | O(1) instant | O(1) instant |
