bugger.
All challenges/Pythoneasythe-cache-that-forgets-v1
THE INVESTIGATION

The cache that forgets

A cached result gets computed again. Only some values trigger it.

CachingState

What’s going wrong

A lookup service should evaluate each unique key once per batch. A repeated key sometimes runs the lookup again, making the call counter too high.

Input is a JSON array of records with `key` (string) and `value` (any JSON value). The first record for a key supplies its value. Later records with that key must reuse the first result, even if they supply a different value. Print compact JSON with `values` in input order and `calls`, the number of actual lookups. An empty batch performs zero lookups.

Reproduce the repeated-null case, then fix `resolve` without changing the input/output contract.

Expected behavior

Every unique key is evaluated once. Every JSON value, including null, false, zero, and empty strings, is a valid cached result.

Reproduction

01 Repeated null
[{"key":"a","value":null},{"key":"a","value":null}]
{"values":[null,null],"calls":1}
02 Ordinary result
[{"key":"x","value":7},{"key":"x","value":9}]
{"values":[7,7],"calls":1}

Before you begin

  • Functions
  • Dictionaries
  • JSON values

Need a nudge?

Reveal one investigation hint at a time. Try each clue before opening the next.

    The bug is intentional. Run the starter code to see it fail, then work toward a fix. Difficulty is provisional.
    Read-only preview
    Ready when you are
    Every fix starts with a failing test.

    Read the report, then sign in to start your investigation.