Command Palette

Search for a command to run...

Hectal
Phase 0: Start Here: What an LLM Is and Why Engineering Matters
LLM Engineering · Exercise 1 of 5Next
Beginner

Count the next words

Write next_counts(text, word) that returns a dictionary: for every place word appears in text (split on spaces), count the word right after it.

If word never appears, or only appears as the last word, return an empty dictionary {}.

What Check tests

  1. next_counts("the cat sat on the mat", "the") is {"cat": 1, "mat": 1}
  2. Repeated pairs are counted
  3. A word that never appears gives {}
  4. The last word has no next word

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.