Skip to content
← All tracks

Stdlib Mastery

Python

`itertools`, `functools`, `collections`, `pathlib`, `decimal`, `datetime` — the batteries you already shipped and mostly do not use.

This track is written for Python, which isn't the mode you're browsing in.

0 / 25 solved · 30 articles
  1. 1. Counter: counting, tallying, multiset arithmetic Read
  2. 2. Not solved yet. Counter: top n-grams with deterministic ties
  3. 3. defaultdict vs setdefault vs dict.get Read
  4. 4. Not solved yet. defaultdict: group rows, hand back a plain dict
  5. 5. deque: the O(1) ends, maxlen, and rotate Read
  6. 6. Not solved yet. deque: rolling median and the maxlen narrowing
  7. 7. ChainMap: layered configuration and scope stacks Read
  8. 8. Not solved yet. ChainMap: resolve config and keep the provenance
  9. 9. OrderedDict in 2026: the three things dict still cannot do Read
  10. 10. itertools foundations: chain, islice, and the laziness contract Read
  11. 11. Not solved yet. itertools: take n across chunks without over-consuming
  12. 12. groupby: two silent failures, one of which passes your test Read
  13. 13. Not solved yet. groupby: summarise rows without losing half of them
  14. 14. batched: chunking without the off-by-one Read
  15. 15. Not solved yet. batched: page a stream, and validate before you yield
  16. 16. pairwise and accumulate: the two loops you stop writing Read
  17. 17. Not solved yet. accumulate and pairwise: max drawdown in one pass
  18. 18. tee and product: the two itertools functions that will OOM you Read
  19. 19. The rest of itertools, one justification each Read
  20. 20. cache and lru_cache: the decorator that deletes your signature Read
  21. 21. Not solved yet. cache: memoised edit distance behind a validated wrapper
  22. 22. lru_cache on methods: the leak that profiles as 'objects that should be dead' Read
  23. 23. Not solved yet. lru_cache on a method: fix the unbounded instance leak
  24. 24. cached_property: the 3.12 lock removal and the __slots__ crash Read
  25. 25. Not solved yet. cached_property: compute once, release with the instance, invalidate on demand
  26. 26. singledispatch: open extension, and the exhaustiveness you give up Read
  27. 27. Not solved yet. singledispatch: a JSON encoder callers can extend from outside
  28. 28. partial, partialmethod, and the 3.14 change that binds self Read
  29. 29. Not solved yet. partial: a signature-preserving retrier, and the 3.14 descriptor change
  30. 30. reduce: the narrow band where it earns its place Read
  31. 31. wraps: the eight attributes a decorator has to carry Read
  32. 32. total_ordering: six comparisons from two, and the NotImplemented rule Read
  33. 33. Not solved yet. total_ordering: SemVer, where pre-release sorts before release
  34. 34. contextmanager: the try/finally that is not optional Read
  35. 35. Not solved yet. contextmanager: temporarily patch an attribute, and put it back
  36. 36. ExitStack: N resources when N is a runtime value Read
  37. 37. Not solved yet. ExitStack: all-or-nothing acquisition of N resources
  38. 38. suppress, closing, nullcontext, chdir Read
  39. 39. Not solved yet. nullcontext and suppress: use the stream you were given, close only what you opened
  40. 40. asynccontextmanager, aclosing, AsyncExitStack Read
  41. 41. Not solved yet. aclosing: release the connection on break, error and cancellation
  42. 42. pathlib: path: str accepts a URL, an SQL fragment, or a user's name Read
  43. 43. Not solved yet. pathlib: safe_join, or how to not serve /etc/passwd
  44. 44. pathlib advanced: walk, glob, and the 3.13 change nobody announced Read
  45. 45. Not solved yet. walk: prune the subtree, not just the results
  46. 46. StrEnum: the migration path out of a module of string constants Read
  47. 47. Not solved yet. StrEnum: migrate a module of string constants without breaking callers
  48. 48. Flag and IntFlag: bitmasks that print, iterate and validate Read
  49. 49. Not solved yet. Flag: a permission mask that prints, iterates and refuses bad bits
  50. 50. tomllib: config parsing is where untyped data enters your program Read
  51. 51. Not solved yet. tomllib: turn dict[str, Any] into a typed config, or a named error
  52. 52. datetime: two silent data-corruption sources in one lesson Read
  53. 53. Not solved yet. datetime: reject naive input, and find the next local wall clock
  54. 54. statistics, bisect, heapq: one signature trap each Read
  55. 55. Not solved yet. heapq: a priority queue that is FIFO among equal priorities

Check yourself

4 questions · one attempt each

These do not count toward finishing the track. They are here to catch the things that are easy to read past.

0 / 4

Why can you take the first three of an infinite counter?

list(itertools.islice(itertools.count(), 3))
Question 1 of 4