Log level frequency breakdown
Your task
A CI pipeline emits log lines of the form "<timestamp> <LEVEL> <message>". The on-call engineer wants a quick severity breakdown of a run. Given the lines, return a dictionary mapping each level that actually appears (for example "INFO", "WARN", "ERROR") to the number of lines logged at that level. Levels that never appear must not be keys in the result, and an empty log yields an empty dictionary.
Examples
level_counts(lines: list[str]) -> dict[str,int]Example 1
Input
level_counts(["t1 ERROR db down", "t2 INFO retrying now", "t3 ERROR db down"])Output
{"ERROR": 2, "INFO": 1}