Python data engineering interview problem. Difficulty: intermediate. Pattern: Streaming. About 15 minutes. Part of the Pro drill bank.
An event stream should be flushed to disk in batches of at most N items so a crash only loses one batch.
Split a sequence into batches of a given size.
Input: batched([1, 2, 3, 4, 5], 2) Output: [[1, 2], [3, 4], [5]] This input follows the stated rules and produces this output.
Topics: lakebench, python, generators.
More Python interview questions · All interview problems · Learn data engineering
Interview-style drill: Write a generator that yields fixed-size batches from an arbitrarily long iterable.
Split a sequence into batches of a given size.