Command Palette

Search for a command to run...

Hectal
Phase 7: Query Understanding
RAG and Vector Search · Exercise 5 of 6 PreviousNext
Intermediate

Route a question, with a safe default

Write route(question, rules, default). rules is a list of (name, words, minimum) where words is a set. Count how many of a rule's words appear in the question (lower-cased words, each counted once).

Return the name of the rule with the highest count, but only if that count reaches its minimum and no other rule has the same highest count. In every other case return default.

What Check tests

  1. A clear winner above its minimum
  2. Below the minimum goes to the default
  3. No match goes to the default
  4. A tie goes to the default
  5. Case does not matter

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.