Joel Stevick

The Python readiness check · 60 minutes · 2 tasks

Mid-level Python skills assessment practice

Developers with two to five years of Python, applying for a mid-level role that expects classes, the standard library and code that scales.

A new test every time, written by Claude, like the screens on HackerRank, CodeSignal and Codility: 60 minutes, 2 tasks, hidden tests that score it and a review of your code. Your first mid-level test is free; after that $5 a test, or $19 for five.

The topics

Classes, Comprehensions, Error handling, The collections module, itertools, Dates and times, Parsing text, Complexity.

A sample task: Summarize a log

A task from this level, whole, as the test shows it. Your test is a new one, written for you.

Write summarize(lines). Each line of a log is a timestamp, a level and a message, separated by whitespace: 2026-03-01T12:00:05 ERROR disk full. The message may be missing. The level is one of INFO, WARNING or ERROR, in capitals. Return a dict with four keys:

  • "counts": a dict from each level that appears to how many lines have it;
  • "first" and "last": the earliest and latest timestamps, as datetime objects (the lines are not always in order), or None when no line counted;
  • "skipped": how many lines were not counted because their timestamp does not parse (ISO 8601, as datetime.fromisoformat reads it) or their level is missing or not one of the three.

Blank lines (empty or only whitespace) are ignored: neither counted nor skipped.

summarize(["2026-03-01T12:00:05 ERROR disk full", "oops"])
# {"counts": {"ERROR": 1}, "first": datetime(2026, 3, 1, 12, 0, 5),
#  "last": datetime(2026, 3, 1, 12, 0, 5), "skipped": 1}

Starter code

from datetime import datetime


def summarize(lines):
    # Return {"counts": ..., "first": ..., "last": ..., "skipped": ...}.
    return {"counts": {}, "first": None, "last": None, "skipped": 0}

Example tests

from datetime import datetime


def test_example_one_good_one_bad():
    got = summarize(["2026-03-01T12:00:05 ERROR disk full", "oops"])
    assert got == {"counts": {"ERROR": 1}, "first": datetime(2026, 3, 1, 12, 0, 5),
                   "last": datetime(2026, 3, 1, 12, 0, 5), "skipped": 1}


def test_example_empty():
    assert summarize([]) == {"counts": {}, "first": None, "last": None, "skipped": 0}

Hidden tests (12 of them for this task) check the edge cases the statement names. You never see them, as on a real screen.

A sample report

A real graded submission with mistakes: its test results come from the harness run by a local Python 3.9.6 (npm run assessment:anchors:local) on 2026-11-22; its review was written by hand as the sample review, for a submission whose test results come from a real run of the harness; not a live model run.

Close to ready for a mid-level Python screen

15 of 23 hidden tests passed. Ready means at most one hidden test failed on every task; close means at least 60% of them passed overall.

Both answers work on the happy path; the log summary trusts the input too much and the cache forgets that a read is a use. Close, and the fixes are small.

Task 1: Summarize a log

7 of 12 hidden tests passed.

  • test_first_is_earliest_not_first_line: AssertionError
  • test_last_is_latest: AssertionError
  • test_bad_timestamp_skipped: ValueError: month must be in 1..12
  • test_blank_lines_ignored: AssertionError
  • test_extra_spaces_between_fields: AssertionError

Summary. The level check and the counting are right. The function assumes the lines are in order, crashes on a bad timestamp, and splits on single spaces.

What failed and why, most important first:

  1. test_bad_timestamp_skipped: datetime.fromisoformat raises ValueError on "2026-13-01T00:00:00" and nothing catches it, so one bad line ends the whole summary. Wrap the parse in try/except ValueError and count the line as skipped.
  2. test_first_is_earliest_not_first_line: first is times[0], the first line's time, but the statement says the lines are not always in order. Use min(times) and max(times), or track both as you go (test_last_is_latest fails for the same reason).
  3. test_extra_spaces_between_fields: line.split(" ") makes empty strings out of repeated spaces, so the level is not parts[1]. line.split() with no argument splits on any run of whitespace.
  4. test_blank_lines_ignored: A blank line is counted as skipped; the statement says to ignore it. Check line.strip() first and continue.

Edge cases. Unknown and lower-case levels are skipped correctly, and an empty log gives None for both times. Bad timestamps, blank lines and unordered lines are missed.

Complexity. Linear in the number of lines, which is right. Keeping every timestamp in a list costs memory you do not need: two running values are enough.

Readability. Clear names and a flat loop. The levels tuple belongs in a module constant so it is not rebuilt for every line.

Your code
from datetime import datetime


def summarize(lines):
    counts = {}
    times = []
    skipped = 0
    for line in lines:
        parts = line.split(" ")
        if len(parts) < 2 or parts[1] not in ("INFO", "WARNING", "ERROR"):
            skipped += 1
            continue
        counts[parts[1]] = counts.get(parts[1], 0) + 1
        times.append(datetime.fromisoformat(parts[0]))
    return {
        "counts": counts,
        "first": times[0] if times else None,
        "last": times[-1] if times else None,
        "skipped": skipped,
    }
A reference solution
from datetime import datetime

LEVELS = {"INFO", "WARNING", "ERROR"}


def summarize(lines):
    counts = {}
    first = last = None
    skipped = 0
    for line in lines:
        if not line.strip():
            continue
        parts = line.split(maxsplit=2)
        if len(parts) < 2 or parts[1] not in LEVELS:
            skipped += 1
            continue
        try:
            when = datetime.fromisoformat(parts[0])
        except ValueError:
            skipped += 1
            continue
        counts[parts[1]] = counts.get(parts[1], 0) + 1
        if first is None or when < first:
            first = when
        if last is None or when > last:
            last = when
    return {"counts": counts, "first": first, "last": last, "skipped": skipped}

Task 2: A least-recently-used cache

8 of 11 hidden tests passed.

  • test_capacity_zero_raises: AssertionError: LRUCache(0) did not raise ValueError
  • test_negative_capacity_raises: AssertionError: LRUCache(-3) did not raise ValueError
  • test_get_refreshes_recency: AssertionError

Summary. Eviction on put works and the size stays at the capacity. A get does not move the key to the most recent end, and the capacity is not validated.

What failed and why, most important first:

  1. test_get_refreshes_recency: get only reads self.values, so a key that is read often is still evicted as if it were never used. Reading must move the key to the end of the order, as put does.
  2. test_capacity_zero_raises: The statement asks for ValueError when capacity is below 1; the constructor accepts anything (test_negative_capacity_raises fails the same way).

Edge cases. Replacing an existing key, capacity one and storing None all work.

Complexity. self.keys.remove(key) and self.keys.pop(0) are linear in the cache's size, so each put is O(n), not the constant time the statement asks for. It passed the timing test here, but a larger cache would not. collections.OrderedDict gives move_to_end and popitem(last=False) in constant time.

Readability. Two structures that must be kept in step (a list and a dict) are where the recency bug came from. One OrderedDict removes that whole class of mistake.

Your code
class LRUCache:
    def __init__(self, capacity):
        self.capacity = capacity
        self.keys = []
        self.values = {}

    def get(self, key):
        return self.values.get(key)

    def put(self, key, value):
        if key in self.values:
            self.keys.remove(key)
        self.keys.append(key)
        self.values[key] = value
        if len(self.keys) > self.capacity:
            oldest = self.keys.pop(0)
            del self.values[oldest]

    def __len__(self):
        return len(self.keys)
A reference solution
from collections import OrderedDict


class LRUCache:
    def __init__(self, capacity):
        if capacity < 1:
            raise ValueError("capacity must be at least 1")
        self.capacity = capacity
        self.entries = OrderedDict()

    def get(self, key):
        if key not in self.entries:
            return None
        self.entries.move_to_end(key)
        return self.entries[key]

    def put(self, key, value):
        if key in self.entries:
            self.entries.move_to_end(key)
        self.entries[key] = value
        if len(self.entries) > self.capacity:
            self.entries.popitem(last=False)

    def __len__(self):
        return len(self.entries)

A proctored screen would have flagged 0 pastes into the editor and 1 time the tab was left. Nothing was blocked here; on a real screen these are often reviewed by a person.

What to practise

Start a test

All four levels and the questions people ask: the Python readiness check.