Intermediate
Find passages that contain a phrase
docs is a dict of passage id to text, and tokenize(text) is given.
Write phrase_docs(docs, phrase) returning the list of passage ids (in the order of docs) in which the words of phrase appear next to each other, in order. phrase is a string such as "ride credit"; tokenise it too. An empty phrase matches nothing.
What Check tests
- Adjacent words in order match
- Both words present but not adjacent do not match
- Case and punctuation are ignored
- A single word works
- An empty phrase matches nothing
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.