Your question is Process a Large File Line by Line. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Fractal analytics pipelines may receive log files that are too large to load into memory. Write a function that processes an iterable of log lines one at a time and summarizes lines containing a target keyword.
A line matches when the keyword appears as a case-sensitive substring. Return the total number of matching lines and the zero-based line numbers of the first three matches. The input may be a file object, generator, or list, so your solution must not convert the entire iterable to a list.
Implement process_log_lines(lines, keyword).
lines is an iterable of strings. Each string represents one line and may include a trailing newline character.keyword is a non-empty string.{"matching_count": integer, "first_matches": list of integers}.first_matches contains at most three zero-based line numbers, in ascending order.def process_log_lines(lines, keyword):