Python for a Coding Assessment
A refresher path through the Python graph for someone who has written Python before and has an assessment coming: run and read, rebuild the core, then work the way an assessment expects.
I can say how the running time and memory of a piece of Python grow with its input, name the operation responsible, and measure to check that I am right.
Reasoning about how code behaves as the input grows, in Python’s terms: the costs its own data structures have, and what the interpreter does that a language with manual memory does not.
In scope: reading growth off a function, the common quadratic mistakes, the difference between a constant factor and a growth rate, and measuring. Out of scope: proving bounds formally, amortised analysis, and profiling a large system.
Count how many times the innermost work happens as a function of input size n.
n items is linear, O(n).n, is O(n²) — a thousand items becomes a million operations.The line to find is the one executed most, not the one that looks complicated.
for item in items: if item in seen_list: # walks seen_list every time ...Membership in a list is O(n), so this is O(n²) and it looks like two innocent lines. A set or a dict
makes the test O(1) and the whole loop linear. This is the single highest-value thing in the node,
and the reason choose-a-python-data-structure comes first.
Its cousins: building a string with += in a loop (each addition copies the whole string; use
join), and calling list.insert(0, x) repeatedly (each shifts everything; use a deque).
A change that makes code twice as fast has not changed how it grows. At a thousand items nobody notices; at ten million, the growth rate decides whether the program finishes. Fix the growth first, then, if it still matters, the constant.
Python’s constants are large — an interpreted loop is far slower than a C loop — which is why pushing work into built-ins, comprehensions and library functions written in C often beats micro-optimising Python statements.
timeit runs a snippet many times and reports the best result, avoiding the noise of a single run.
Measure the real input size, not a toy one: the whole point of growth is that behaviour at ten items
tells you nothing about ten million.
Give learners a function that is accidentally quadratic and a file big enough to make it hurt. Ask for the growth rate first, the offending line second, and the fix third — in that order, because guessing at fixes before naming the cause is the habit to break.
Then have them time both versions at two input sizes, so they see the growth rather than a single number.
| Resource | Kind | Cost | Provider |
|---|---|---|---|
| Python wiki: time complexity of built-in operations | reference | free | Python Software Foundation |
| timeit: measure execution time of small code snippets | reference | free | Python Software Foundation |
A refresher path through the Python graph for someone who has written Python before and has an assessment coming: run and read, rebuild the core, then work the way an assessment expects.
A timed take-home in the shape real hiring uses: read messy data, compute a result, test it, and hand over a repository someone else can run.
The holder can take an unfamiliar problem, write a tested Python solution someone else can run, and explain what it costs.
Nothing to show yet. The publisher last published on 2026-09-20, and no aggregate for this outcome has reached the 50 learners a number needs. Open Degree does not track learners. About learner evidence.