01 · Basics
- variables
- types
- f-strings
- input/output
End of the Python Course
Congratulations: you have made it through the 9 modules of the Python Course — from your very first variables and if statements to @dataclass, contextmanager, and @decorator. Below is a map of everything you have mastered and a three-step final challenge.
Imagine a small utility that parses text logs, aggregates counts, and handles errors robustly. Build the three parts: the parser, the aggregator, and the retry decorator. Each step combines concepts from the modules you have studied — no new lessons.
Write parole(testo): returns a list of all words in lowercase (sequences of alphanumeric characters). Module 8 (re) + Module 4 (string methods).
Define parole(testo: str) -> list[str] which returns all the "words" of the text (re.findall of \w+) all in lowercase. Example: parole("Ciao Mondo, ciao!") -> ["ciao", "mondo", "ciao"].
re.findall(r"\w+", testo) and list comprehension with .lower().
Solution available after 3 attempts
Count how many times each word appears and return the top N most frequent ones. Module 8 (collections) + Module 6 (iterators).
Define top_parole(testo: str, n: int) -> list[tuple[str, int]] which uses parole() (reusing the function from step 1) and Counter to return the n most frequent words, sorted from most common down.
Counter(parole(testo)).most_common(n) does all the work.
Solution available after 3 attempts
Write a decorator that retries a function up to N times if it raises an exception. Module 9 (decorators) + Module 2 (try/except).
Define retry(tentativi: int) as a parameterized decorator. The decorated function is called up to "tentativi" times: if it raises an exception, it retries; if all attempts fail, let the last exception propagate. Use functools.wraps.
retry(n) returns a decorator. The decorator returns a wrapper. The wrapper loops n times: try calls the function, except stores the exception and continues. If the loop completes without success, raise the stored exception.
Solution available after 3 attempts
A single page with all the essential syntax of modern Python, ready to keep handy while you code.
The best way to solidify your knowledge is free practice. Open an editor (or the Python Playground) and try to rewrite the most complex exercises from memory, or build small scripts: a log analyzer, a JSON data scraper, a small CLI tool using argparse.