Intermediate
A cache that cannot cross tenants
Write cached_answer(cache, tenant, question, search). cache is a dict, and search(tenant, question) returns the answer text.
Build the key from the tenant and the question's lower-case words joined by single spaces (use re.findall(r"[a-z0-9]+", ...)), separated by a bar. If the key is not in cache, call search once and store the result. Return the answer.
What Check tests
- The same tenant and question search once
- Different tenants never share an answer
- Capitalisation and punctuation do not matter
- The tenant is part of the key
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.