os, sys, itertools, json and Counter
json.dumps(..., indent=2) makes readable text; json.loads brings it back, and the round trip gives an equal dictionary. Counter comes from collections (Topic 4.10).
Python ships with hundreds of ready-made modules: maths, randomness, dates and time zones, the operating system, iteration tools, statistics and JSON. Knowing what exists, and how to read the documentation, saves you from rewriting what is already built, tested and fast.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Use statistics to print the mean and median of [4, 8, 15, 16, 23, 42].
Call random.seed(1), then print a list of three dice rolls made with random.randint(1, 6). Then explain in one sentence why running the program again gives the same three numbers.
Print how many days there are from date(2026, 10, 9) to date(2026, 12, 25) (subtract the earlier date from the later one and use .days).
Put the dictionary {"name": "Asha", "scores": [90, 85]} in a variable, then use json.dumps to print it with an indent of 2 and sorted keys.
Explain it without notes
What is the standard library, and how do you know a module belongs to it?
Why do tests and experiments call random.seed(...), and why not use random for passwords?
How should an application treat time zones?
How do you find out how to use a module you have never seen?
Expected output
python: (3, 13)
argv type: list
missing var: default
path join: data/a.txt | splitext: ('report.final', '.pdf')
cwd empty folder has files: []
[10, 15, 20, 25]
[1, 2, 'a', 'b']
[('A', 'B'), ('A', 'C'), ('B', 'C')]
[(0, 0), (0, 1), (1, 0), (1, 1)]
[(1, 4), (4, 9), (9, 16)]
{
"user": "Asha",
"items": [
{
"sku": "A1",
"qty": 2
}
],
"paid": true,
"note": null
}
True 2
[('i', 4), ('s', 4)]