🔶 Python: The Core Data Structures
List [1, 2, 3] — ordered, mutable, allows duplicates.
Tuple (1, 2, 3) — ordered, immutable, allows duplicates. Faster than lists, usable as dict keys.
Set {1, 2, 3} — unordered, mutable, no duplicates. Membership check is O(1) vs O(n) for lists.
Dict {'key': 'val'} — key-value pairs, ordered (Python 3.7+), O(1) lookup.
The interview trick: "Remove duplicates from a list while preserving order?"
list(dict.fromkeys(my_list)) # Dict preserves insertion order, rejects dup keys
Practice Questions
Q: Which data structure would you use if you need to check whether an item exists in a collection of 10 million elements, and why?