Mission 02 / CODE / AUTOMATION
Python Engineering
Use Python syntax, variables, collections, functions, and exceptions to parse a small event log.
Briefing
Parse an authentication log
Python programs combine values, control flow, and reusable functions. Run the starter program in a short-lived browser worker; it has no access to the application server or your files.
Syntax is structure
Parentheses call functions and group expressions, brackets create lists and index values, and braces create dictionaries. Names bind to values with `=`. Indentation defines blocks for functions, loops, and conditional statements.
Choose a collection for the job
A list keeps an ordered sequence. A dictionary maps a key such as `result` to a value such as `failed`. This lab uses a list of dictionaries, a common shape for small JSON event records. A list comprehension filters records without changing the originals.
Parse, then report
A parser turns raw input into structured values before analysis. For a larger log, read one line at a time, handle malformed entries with `try`/`except`, and test both expected and missing fields. This starter uses a short, synthetic event list and prints only a count.
Practical exercise
Run the mission
Run the parser. It should count only failed events and print `2 failed login attempts`.
Progressive hint
Filter `events` on the `result` key, then use `len()` on the filtered list. Run the code and submit its actual output.
Need another hint?
Compare each dictionary's `result` to `failed`, then print the filtered list's length.
Run the starter to see observable output. Code is saved in this browser.
Pyodide · Python in WebAssembly · isolated short-lived browser worker
Knowledge check