Back to Practice
#0226
Parse Error Log Counts
EasyPython15 min10 XP
Problem
Each log line starts with a level like INFO, WARN, or ERROR. Return counts by level.
Why This Matters
Log parsing is a realistic version of string splitting and dictionary counting.
Function Signature
def count_log_levels(log_text):
Examples
Example 1
Input"INFO started\nERROR failed\nINFO stopped"
Output{"INFO": 2, "ERROR": 1}
INFO appears twice and ERROR appears once.
Constraints
- Return the exact requested value.
- Handle edge cases cleanly.
- Prefer readable Python before micro-optimizing.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Input"INFO started\nERROR failed\nINFO stopped"
Expected{"INFO": 2, "ERROR": 1}
INFO appears twice and ERROR appears once.
Hidden Test Categories
blank linessingle-word log linesthree or more levels