Write pipeline(source, n) returning a generator that, from an iterator of log records
({"level": str, "ms": int}):
"ERROR",ms value,n batches.It must be lazy: it should pull from source only as many records as needed. The harness counts how
many records you consumed.
Implement pipeline. Input: source: iterator of dict, n: int. Returns: generator of list[int].
The first batch is complete after the fourth record, so the last two are never read.
This code runs before yours (fake clients, clocks and the test harness). You can use its names; don't edit them.
def __harness__(fn, records, n):
pulled = {"count": 0}
def source():
for r in records:
pulled["count"] += 1
yield r
gen = fn(source(), n)
is_generator = hasattr(gen, "__next__")
batches = list(gen)
return {"batches": batches, "pulled": pulled["count"], "lazy": is_generator}
def pipeline(source, n):
values = [r["ms"] for r in source if r["level"] == "ERROR"]
return [values[i:i + 3] for i in range(0, len(values), 3)][:n]
Run executes the public tests. Submit grades against public and hidden tests.
Write pipeline(source, n) returning a generator that, from an iterator of log records
({"level": str, "ms": int}):
"ERROR",ms value,n batches.It must be lazy: it should pull from source only as many records as needed. The harness counts how
many records you consumed.
Implement pipeline. Input: source: iterator of dict, n: int. Returns: generator of list[int].
The first batch is complete after the fourth record, so the last two are never read.
This code runs before yours (fake clients, clocks and the test harness). You can use its names; don't edit them.
def __harness__(fn, records, n):
pulled = {"count": 0}
def source():
for r in records:
pulled["count"] += 1
yield r
gen = fn(source(), n)
is_generator = hasattr(gen, "__next__")
batches = list(gen)
return {"batches": batches, "pulled": pulled["count"], "lazy": is_generator}
def pipeline(source, n):
values = [r["ms"] for r in source if r["level"] == "ERROR"]
return [values[i:i + 3] for i in range(0, len(values), 3)][:n]
Run executes the public tests. Submit grades against public and hidden tests.