Loading lesson…
Level 1 · Apprentice0 XP
yield for streams of tokens and big files, and with for resources that must be closed.
Step 1 / 6
ProblemA script reads a 20 GB JSONL dataset with f.readlines() to clean it. The laptop runs out of memory before the first line is processed.
← → step
Before this: Functions, closures and decorators
🛠️ Your turn
Reading is not the skill, doing is. Try for ten minutes before you open the hint. Getting stuck first is what makes the solution stick.
1.Write a generator that reads a large JSONL file lazily, a second that batches items, and a @contextmanager that times a block and logs the duration. Process a 1 GB generated file and check memory stays flat.