HTTP status code classes

Write codeEasy10 min

Your task

An API gateway access log has one line per request: "<timestamp> <method> <path> <status>", where status is a three-digit HTTP code like 200 or 503. For a traffic summary, group codes into classes by their first digit: "2xx", "3xx", "4xx", "5xx", and so on. Return a dictionary mapping each class that occurs in the log to its request count. Classes with no requests must be absent, and an empty log returns an empty dictionary.

Examples

status_class_counts(lines: list[str]) -> dict[str,int]
Example 1
Inputstatus_class_counts(["t1 GET /home 200", "t2 GET /missing 404", "t3 POST /pay 500", "t4 GET /home 204"])
Output{"2xx": 2, "4xx": 1, "5xx": 1}