# Why do I understand code but forget how to write it?

> Turn a familiar-looking solution into something you can reconstruct. Use a small Python exercise, a changed requirement and a follow-up attempt without hints.

- Canonical HTML: [https://unrust.dev/blog/understand-code-but-cant-write-it](https://unrust.dev/blog/understand-code-but-cant-write-it)
- Markdown representation: [https://unrust.dev/blog/understand-code-but-cant-write-it/index.md](https://unrust.dev/blog/understand-code-but-cant-write-it/index.md)

Published: 2026-10-28. By the Unrust team.

## Check what you can produce with the example closed

Start with one tiny requirement, close the solution, and write an attempt. Following an explanation gives you the author's variable names, steps and structure. A blank editor asks you to supply those choices. If you can follow the code but cannot start, practise making the choices explicit rather than replaying the same explanation.

You do not need to memorise an entire library. Separate a missing API detail from a missing plan. Writing ‘visit each reading, compare it with the threshold, increment a counter’ is already a plan you can inspect. If that is clear but the loop syntax is missing, look up that specific syntax after your first attempt.

## Try it: predict, explain, then reconstruct

This Python function counts readings at or above a threshold. Write the two outputs without running it. Explain why a value equal to the threshold qualifies. Then cover the function and reconstruct it using only that requirement and the two calls.

```python
def count_ready(readings, threshold):
    count = 0
    for reading in readings:
        if reading >= threshold:
            count += 1
    return count

print(count_ready([0, 4, 4, 9], 4))
print(count_ready([], 4))
```

### Answer and explanation

The outputs are 3 and 0. Both readings of 4 qualify, as does 9. With no readings, the loop body never runs and the initial counter is returned.

For a fresh attempt, change the requirement to strictly above the threshold. The same calls should then produce 1 and 0. The necessary change is >= to >. If you can explain that change before seeing code, you are checking the requirement rather than recalling the old answer.

## Turn the mistake into a specific practice target

If you returned 2 for the first call, inspect whether you counted distinct values instead of readings. If you returned 1, inspect the boundary comparison. If you returned nothing for the empty input, check where you placed the return statement. These are different mistakes and deserve different follow-up tasks.

Keep a note with the requirement, your initial attempt and the smallest correction. A note that says ‘Python loops’ is too broad to guide tomorrow's practice. A note that says ‘return after the loop so an empty input also returns zero’ tells you what to test next.

## Revisit the idea with a different surface

Try a new version the next day: count messages longer than a specified length, including an empty list and a message exactly at the boundary. Later, change counting into collecting the matching messages. This is a suggested practice schedule; adjust it to what you can actually reconstruct.

Attempt first, inspect feedback second, and explain the correction last. When stuck, make the task smaller or request one targeted hint. Record that help so you do not confuse a guided solution with an independent attempt. Reading the answer can be part of learning; it just answers a different question from doing the task with the answer hidden.

## Use Unrust for a focused next step

Unrust separates recall from tracing and comprehension in its free diagnostic. That gives you a way to notice a difference between following a program and supplying a missing piece. It is a limited sample of current performance, not a complete assessment of everything you know.

The optional practice loop uses spaced repetition and skill-level progression to choose further work. Pair that structured practice with small functions in your own editor. If you are new to programming, keep using a beginner course for instruction: Unrust is practice and a diagnostic, not a replacement for learning the language from scratch.

## Questions from the community

These public discussions informed the question this article answers. They reflect personal experiences, not evidence of how common a problem is or what caused it. Sources checked October 28, 2026.

[Reddit: a Python learner cannot recreate yesterday's work](https://www.reddit.com/r/learnpython/comments/1uh6smr/i_forget_everything_i_learn_after_a_day_is_ai/)
The question distinguishes understanding a copied solution from writing a new attempt the next day.

[Quora: improving programming skills without forgetting concepts](https://www.quora.com/How-do-you-improve-your-programming-skills-and-make-sure-not-to-forget-the-concept-next-time)
Readers ask how to make concepts available again when they need to implement something.

## References and next steps

[Python tutorial: loops and defining functions](https://docs.python.org/3/tutorial/controlflow.html)

[Practise code recall with small reconstruction tasks](https://unrust.dev/guides/code-recall/index.md)

## See how recall compares with tracing

Start with Unrust's free diagnostic, then choose practice for the skill that needs attention. Attempt each item before opening help.

[Check my unassisted skills](https://unrust.dev/diagnostic/index.md)
