Software Engineer (SDE)pythonbeginner3 interactive MCQs in app
Lists & Tuples: Operations & Slicing
list aliasing vs shallow slicing copiestuple immutability and hashabilityO(1) append/pop() vs O(n) pop(0)
Core Concept
Lists (`[...]`) are mutable dynamic arrays supporting O(1) append/pop-end and O(k) slicing (`items[start:stop]`, which copies a slice). Tuples (`(...)`) are immutable fixed records suitable for heterogeneous values `(user_id, score)` and dictionary keys when all elements are hashable.
Worked Example
`record = ("u1", 90)` can sit in a `set`, whereas `["u1", 90]` raises `TypeError: unhashable type: list`. `scores[-2:]` returns the last two items cleanly without mutating `scores`.
Common Pitfall
`b = a` aliases the same list instead of copying (`a.copy()` or `a[:]`), and `a.pop(0)` shifts every remaining element in O(n) time.
Recommended Readings & Practice
Practice Lists & Tuples: Operations & Slicing with 3 graded MCQs & written feedback.
Take SOARDO’s free 12-question diagnostic to see how strong you are across your target role and unlock adaptive daily missions.