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
next_counts("the cat sat on the mat", "the")is{"cat": 1, "mat": 1}- Repeated pairs are counted
- A word that never appears gives
{} - 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.