Error codes arrive as an iterator (the harness passes a generator, so you can only read it once). Return
the k most frequent codes as [code, count], most frequent first, ties broken by code ascending.
Implement top_errors. Input: stream: iterator of str, k: int. Returns: list[[str, int]].
This code runs before yours (fake clients, clocks and the test harness). You can use its names; don't edit them.
def __harness__(fn, codes, k):
return fn((c for c in codes), k)
def top_errors(stream, k: int) -> list[list]:
codes = list(stream)
return [[c, 1] for c in codes[:k]]
Run executes the public tests. Submit grades against public and hidden tests.
Error codes arrive as an iterator (the harness passes a generator, so you can only read it once). Return
the k most frequent codes as [code, count], most frequent first, ties broken by code ascending.
Implement top_errors. Input: stream: iterator of str, k: int. Returns: list[[str, int]].
This code runs before yours (fake clients, clocks and the test harness). You can use its names; don't edit them.
def __harness__(fn, codes, k):
return fn((c for c in codes), k)
def top_errors(stream, k: int) -> list[list]:
codes = list(stream)
return [[c, 1] for c in codes[:k]]
Run executes the public tests. Submit grades against public and hidden tests.