You’ll be able to
- Use
Counterto count occurrences in a sequence - Use
defaultdictto avoidKeyErrorboilerplate - Use
dequefor O(1) appends and pops on both ends - Use
namedtuplefor lightweight structured records
Loading lesson…
Why this matters
Counter, defaultdict, and deque are the difference between clean code and reinventing wheels in interviews and production. deque is O(1) at both ends — list.pop(0) is O(n), a bug that quietly slows queue workers.
Common pitfalls
- Using
dict.get(k, []).append(v)instead ofdefaultdict(list)— the.getversion never mutates the dict. - Using
listas a FIFO queue —pop(0)is O(n); reach forcollections.dequefor O(1) popleft. - Sorting a
Countermanually when.most_common(n)already returns the top-n by count.