Beginner
Generate greedily, with a stop rule
table maps a word to a dictionary of next-word counts. Write generate(table, start, max_tokens) that returns a list of words starting with start.
Each step adds the most frequent next word of the last word; break ties by taking the alphabetically first word. Stop when the list has max_tokens words, when the last word is ".", or when the last word has no next words in the table.
What Check tests
- Picks the most frequent word and breaks ties alphabetically
- Stops at
max_tokenswords - Stops when the last word has no next words
max_tokensof 1 returns just the start
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.