Standard Library Power Tour
Lesson 5 of 5 · View course roadmap
Learn the idea
Python ships "batteries included" — a huge standard library. The modules you'll reach for weekly:
json—json.dumps(obj)/json.loads(text): convert between Python and JSONdatetime— dates, times, differences:date.today(),timedelta(days=7)random—choice,shuffle,randintcollections.Counter— count things in one linepathlib.Path— modern file paths
Counter deserves special love: Counter("mississippi").most_common(2) → [('i', 4), ('s', 4)]. Before writing a loop, ask: "does the stdlib already do this?" It usually does.
Where you'll use this
'Batteries included' is why Python won ops and data: json for every API, datetime for every schedule, csv for every export, Counter for every 'top N' feature — zero installs required.
Common mistakes
- Rebuilding what exists: hand-rolled JSON parsing, manual date math across month boundaries, DIY counting loops — the stdlib version is tested against edge cases yours will miss.
- json.load vs json.loads (and dump/dumps): the s means string, the plain one takes a file object.
- random for anything security-related — passwords and tokens need the
secretsmodule.
Pro tip
Before writing any utility function, spend 30 seconds checking: does itertools, collections, functools or pathlib already do this? The answer is yes more often than any other language.
Try it yourself
The lesson example is loaded and ready — press Run, then change something and run it again. Breaking it is part of learning. Want a clean slate? Tap “New blank”.
Output appears here…
Pass the challenge +35 XP
Use Counter to find the two most common letters in "abracadabra" and print each as letter count on its own line.
a 5 b 2
for letter, count in Counter(word).most_common(2):
from collections import Counter
for letter, count in Counter("abracadabra").most_common(2):
print(letter, count)
Run your code to check it…
Check your understanding
Your notes (saved on this device)
Tip: use ← and → to move between lessons, ⌘K to search everything.