Parse a log line
Parse 'LEVEL timestamp message' into a group dictionary, or None when malformed.
What you’ll practice
This Level 6 exercise focuses on named regex groups in the Professional curriculum. Solve the challenge prompt above using clear, idiomatic Python and the relevant language or standard-library tools.
Relevant Python reference: re — Regular expression operations.
Sample Test Cases
parse_log('ERROR 14:20:03 timeout'){'level':'ERROR','time':'14:20:03','message':'timeout'}Further Reading
Reference Solution
Reveal Reference Solution
def parse_log(line: str) -> dict[str,str] | None: import re match = re.fullmatch(r'(?P<level>[A-Z]+) (?P<time>\d{2}:\d{2}:\d{2}) (?P<message>.+)', line) return match.groupdict() if match else NonePro Tips & Keyboard Shortcuts
Open VS Code Color Theme Quick Pick to select from 20 dark and light themes.
Open practice settings drawer to toggle line numbers, indenting, font size & hints.
Expand sidebar menu, focus search bar, and highlight search text instantly.
Instantly highlight and focus code editor from anywhere, restoring cursor right where you left off.
Collapse sidebar and close all popups or settings drawers for clean focus view.