Skip to content
LakeBench
ProblemsCommunityPricing
Sign inStart practicing

Lazily read and filter a large log iterator

Python data engineering interview problem. Difficulty: intermediate. Pattern: Strings. About 15 minutes. Part of the Pro drill bank.

A log file is too large to load at once. A helper should iterate lines and yield only the ones that look like errors.

Lazily filter a log iterator to error lines.

Requirements

  • Do not require a full in-memory copy if a generator will do.
  • Keep original line text for matches.

Constraints

  • lines: an iterable of strings (not necessarily a list).
  • Non-error lines are skipped.

Examples

Input: parse_error_lines(['INFO: ok', 'ERROR: disk', 'ERROR: timeout ']) Output: [{'level': 'ERROR', 'msg': 'disk'}, {'level': 'ERROR', 'msg': 'timeout'}] This input follows the stated rules and produces this output.

Topics: lakebench, python, iterators.

More Python interview questions · All interview problems · Learn data engineering

intermediate

Lazily read and filter a large log iterator

Interview-style drill: Given an iterator of raw log lines, return a generator that yields only parsed error entries.

Lazily filter a log iterator to error lines.