Skip to content
← All Python tracks

Everyday Standard Library Tools

Python

Count, group and queue data with collections and heapq, stream it with generators and itertools, and cache results with functools. Clean up with contextlib, and handle paths, enums, TOML config and time zones.

This track uses Python. You can make it your practice mode to browse related content across the site.

25 exercises

30 articles

Explore freely. Sign in to keep your progress.

Your learning sequence

  1. 1 Count Repeated Values with Counter Read
  2. 2 Not solved yet. Count N-Grams and Break Ties with Counter Practice · Easy
  3. 3 Handle Missing Keys with get, setdefault and defaultdict Read
  4. 4 Not solved yet. Group Rows by Key and Return a Plain dict Practice · Easy
  5. 5 Queues and Sliding Windows with deque Read
  6. 6 Not solved yet. Compute a Rolling Median with a Bounded deque Practice · Medium
  7. 7 Priority Queues, Sorted Lists and Summary Statistics Read
  8. 8 Not solved yet. Build a Task Queue That Keeps Arrival Order for Ties Practice · Medium
  9. 9 Layer Configuration with ChainMap Read
  10. 10 Not solved yet. Resolve a Setting and Report the Layer It Came From Practice · Medium
  11. 11 When to Use OrderedDict Instead of dict Read
  12. 12 Generators and One-Shot Iterators Read
  13. 13 Not solved yet. Find the First Error with a Generator Practice · Easy
  14. 14 Take the First Few Items with chain and islice Read
  15. 15 Not solved yet. Take n Items Across Chunks Without Reading Ahead Practice · Easy
  16. 16 Group Adjacent Items with groupby Read
  17. 17 Not solved yet. Count and Total Rows per Key with groupby Practice · Medium
  18. 18 Split a Stream into Batches with batched Read
  19. 19 Not solved yet. Page Records and Check the Size at Call Time Practice · Easy
  20. 20 Adjacent Pairs and Running Totals with pairwise and accumulate Read
  21. 21 Not solved yet. Find the Largest Drop from a Running Peak Practice · Easy
  22. 22 Split an Iterator with tee and Combine Inputs with product Read
  23. 23 Repeat, Pad and Filter Streams with itertools Read
  24. 24 Reuse Earlier Results with cache and lru_cache Read
  25. 25 Not solved yet. Speed Up Edit Distance with a Cached Helper Practice · Medium
  26. 26 Cache Method Results Without Keeping Objects Alive Read
  27. 27 Not solved yet. Give Each Object Its Own Cache Practice · Medium
  28. 28 Compute an Attribute Once with cached_property Read
  29. 29 Not solved yet. Cache a Report Total Until You Clear It Practice · Medium
  30. 30 Choose a Function by Argument Type with singledispatch Read
  31. 31 Not solved yet. Build a JSON Converter Other Code Can Extend Practice · Hard
  32. 32 Write Typed Decorators with wraps and ParamSpec Read
  33. 33 Preset Arguments with partial and partialmethod Read
  34. 34 Not solved yet. Retry a Flaky Call and Preset Arguments with partial Practice · Medium
  35. 35 Combine a List into One Value with reduce Read
  36. 36 Make Objects Sortable with total_ordering Read
  37. 37 Not solved yet. Sort Version Strings with Pre-Releases First Practice · Medium
  38. 38 Write a Context Manager with a Generator Read
  39. 39 Not solved yet. Change an Attribute for One Block and Put It Back Practice · Medium
  40. 40 Clean Up Any Number of Resources with ExitStack Read
  41. 41 Not solved yet. Open a List of Resources and Close Them All Practice · Hard
  42. 42 Small contextlib Helpers for Cleanup and Expected Errors Read
  43. 43 Not solved yet. Close a Stream Only If You Opened It Practice · Easy
  44. 44 Join Paths Safely with pathlib Read
  45. 45 Not solved yet. Keep a Joined Path Inside Its Root Folder Practice · Easy
  46. 46 Walk a Directory Tree and Skip Folders Read
  47. 47 Not solved yet. Find Large Files Without Entering Skipped Folders Practice · Medium
  48. 48 Replace String Constants with StrEnum Read
  49. 49 Not solved yet. Migrate a Status Enum to StrEnum Practice · Medium
  50. 50 Combine Permission Bits with Flag Read
  51. 51 Not solved yet. Decode a Three-Bit Permission Mask Practice · Medium
  52. 52 Read and Check a TOML Config File Read
  53. 53 Not solved yet. Load a Server Config and Report the First Bad Setting Practice · Medium
  54. 54 Store Times in UTC and Schedule in Local Time Read
  55. 55 Not solved yet. Find the Next Daily Run in a Time Zone Practice · Hard

Check yourself

11 questions · not saved while you're signed out

Use these questions to check your understanding and compare explanations. Your score does not affect track completion.

0 / 11 correct

For this plain Enum, what do the two comparisons print?

Choose one answer to reveal the explanations. Answers are kept only while this page is open.

from enum import Enum

class Col(Enum):
    R = 1

print(Col.R is Col(1))
print(Col.R == 1)
Question 1 of 11