Sign in to run and submit your work
Reading is open to everyone. Running code and saving drafts need an account so your work is yours and comes back on your next visit.
or
CODE WORKSPACE
The scheduler writes structured logs in the logfmt style — space-separated key=value pairs, with a value wrapped in double quotes when it contains spaces. The lines also carry a timestamp, a level and a component name that are not pairs at all, and downstream everything is expected to be typed.
Write parse_log_line(line). Return the fields as a dict.
Function to write
parse_log_line(line: str) -> dictA dict of the parsed fields, with unquoted values coerced to bool, int, float, None or str.
How to approach it
Match the pairs with a pattern that knows about quotes; splitting on spaces cannot.
Sample cases
+ 2 held back until you submit
a real log line
A quoted value with spaces, an int, a float, a boolean and a zero that must survive.
Input
Argument 1
'level=INFO status=200 latency=13.5 msg="job failed on shard 3" ok=true retries=0'Returns
{
'level': 'INFO',
'status': 200,
'latency': 13.5,
'msg': 'job failed on shard 3',
'ok': True,
'retries': 0
}an empty line
A blank line parses to an empty dict rather than raising or returning None.
Input
Argument 1
''Returns
{}junk between the pairs
A timestamp, a level, a bracketed component and a trailing comment are not fields.
Input
Argument 1
'2026-03-02T09:00:00Z WARN [scheduler] task=load_orders attempt=2 -- retrying'Returns
{
'task': 'load_orders',
'attempt': 2
}Constraints
true and false become booleans, a whole number becomes an int, a decimal becomes a float, and everything else stays a string.None.None, and a quoted number stays a string.Worked example
Take the first case line:
level=INFO status=200 latency=13.5 msg="job failed on shard 3" ok=true retries=0
The message value contains three spaces. Splitting the line on whitespace produces msg="job as one token, and the rest of the message is scattered across tokens with no equals sign in them — so the field that says what went wrong is the one field that is lost.
retries=0 is the other trap. Coercing it and then testing the result for truthiness treats zero retries as no value, and the field disappears. Zero is a measurement; only an empty value and a dash mean nothing was set.
What this tests
Reading a format by its grammar rather than by splitting on a convenient character, and the difference between a value that is absent and a value that is falsy. Both mistakes produce output that looks fine until the one line that matters.
parse_log_line(line: str) -> dictSubmit for review to find out what your query gets right, what it gets wrong, and how it compares with the best working query for this exercise.
This scenario runs a full workspace — editor, canvas and results side by side. It needs a laptop or desktop to be usable. Open this page on a bigger screen to start building.