teluzia.Cloud Engineer · Day 28
CHAPTER 04 · PYTHON FUNDAMENTALS

Week 4 review, recall and recovery

30–90 min including independent practice3 topicsRecall, catch-up, or rest
LET’S MAKE THIS SIMPLE

What you’re learning today

Rebuild the small log parser without a tutorial and explain each input/output decision. The review should show that you understand the language constructs rather than merely remember a copied script. Input file content begins as text, so numeric fields require deliberate conversion. Lists preserve order and repetition, dictionaries map named keys, sets deduplicate and tuples group fixed sequences. Select a representation according to what information must survive, not the shortest syntax. A function returns a result; printing is a separate side effect. Conditions encode policy boundaries and loops need a termination argument. Modules should avoid operational side effects at import. Divide parsing from file loading so a small function can be checked against one valid or malformed row.

Think of it this way

This review is a practical inspection bench for python values, collections, flow, functions, files and parser setup: explain, reproduce, break safely, diagnose and verify.

TOPIC 01 / 03Step by step

Values and collection semantics

Input file content begins as text, so numeric fields require deliberate conversion. Lists preserve order and repetition, dictionaries map named keys, sets deduplicate and tuples group fixed sequences. Select a representation according to what information must survive, not the shortest syntax. Preserve every log row in a list, count statuses in a dictionary and use a set only for distinct paths rather than event totals. Correct representations keep aggregate meaning intact and prevent a parser from losing repeated requests or interpreting a numeric-looking string as an integer prematurely. Do not convert an event list to a set before counting requests; that removes duplicate observations and can silently underreport identical requests.

WORKED EXAMPLE
Preserve every log row in a list, count statuses in a dictionary and use a set only for distinct paths rather than event totals.
Why this matters

Correct representations keep aggregate meaning intact and prevent a parser from losing repeated requests or interpreting a numeric-looking string as an integer prematurely.

A common trap

Do not convert an event list to a set before counting requests; that removes duplicate observations and can silently underreport identical requests.

Read all topics in this lesson

A complete reference to revisit alongside the guided steps above.

Values and collection semantics

Input file content begins as text, so numeric fields require deliberate conversion. Lists preserve order and repetition, dictionaries map named keys, sets deduplicate and tuples group fixed sequences. Select a representation according to what information must survive, not the shortest syntax. Preserve every log row in a list, count statuses in a dictionary and use a set only for distinct paths rather than event totals. Correct representations keep aggregate meaning intact and prevent a parser from losing repeated requests or interpreting a numeric-looking string as an integer prematurely. Do not convert an event list to a set before counting requests; that removes duplicate observations and can silently underreport identical requests.

WORKED EXAMPLE
Preserve every log row in a list, count statuses in a dictionary and use a set only for distinct paths rather than event totals.

Why this matters

Correct representations keep aggregate meaning intact and prevent a parser from losing repeated requests or interpreting a numeric-looking string as an integer prematurely.

A common trap

Do not convert an event list to a set before counting requests; that removes duplicate observations and can silently underreport identical requests.

Functions and explicit flow

A function returns a result; printing is a separate side effect. Conditions encode policy boundaries and loops need a termination argument. Modules should avoid operational side effects at import. Divide parsing from file loading so a small function can be checked against one valid or malformed row. parse_line("GET /health 200") returns structured data, while the CLI decides how to display it; a missing status is rejected explicitly. Separation makes behavior easier to inspect and reuse and keeps malformed-record tests independent from filesystem setup or terminal output formatting. A function that only prints returns None and cannot serve as reliable parser data; return a value and document the invalid-input result or exception contract.

WORKED EXAMPLE
parse_line("GET /health 200") returns structured data, while the CLI decides how to display it; a missing status is rejected explicitly.

Why this matters

Separation makes behavior easier to inspect and reuse and keeps malformed-record tests independent from filesystem setup or terminal output formatting.

A common trap

A function that only prints returns None and cannot serve as reliable parser data; return a value and document the invalid-input result or exception contract.

Files, exceptions and environments

Read with a declared encoding and close handles using a context manager or appropriate pathlib helpers. Catch specific expected failures. A virtual environment isolates dependencies but not OS privileges. Report accepted and rejected counts, and do not treat a missing file as an empty successful input. A three-line fixture with two valid statuses and one BAD-LINE produces accepted=2 and rejected=1; a nonexistent path must be an error instead. Visible coverage and scoped error handling make the report trustworthy, while environment evidence explains which interpreter ran the rebuilt tool. Broadly catching every exception and outputting zero hides bugs and data loss; distinguish absent input, malformed record and successful empty input under the documented contract.

WORKED EXAMPLE
A three-line fixture with two valid statuses and one BAD-LINE produces accepted=2 and rejected=1; a nonexistent path must be an error instead.

Why this matters

Visible coverage and scoped error handling make the report trustworthy, while environment evidence explains which interpreter ran the rebuilt tool.

A common trap

Broadly catching every exception and outputting zero hides bugs and data loss; distinguish absent input, malformed record and successful empty input under the documented contract.

KEEP THESE WITH YOU

Today’s takeaways

Choose collections by meaning.

Separate parsing and presentation.

Show accepted and rejected coverage.

CLOSE THE LOOP

Ready to complete this day?

Verify your recall or recovery steps, then finish this review day.

Lab steps verifiedReview day: quiz optional