Which Notes Mention It?

Python for AIMedium+10 XP+10

Which Notes Mention It?

A search box needs to know, for every word, which notes it appears in.

Task: write build_index(notes). notes is a list of text notes; note 0 is the first one. Return a dictionary mapping each word to a sorted list of the note numbers it appears in.

  • Split each note into words on spaces. There's no punctuation.
  • Ignore capitals: use small letters for every word.
  • A note number appears once per word, even if the word is repeated inside that note.
  • Return a plain dictionary. No notes means {}.

Examples

notes = ["Buy milk", "milk and eggs milk", "Eggs"]
returns {'buy': [0], 'milk': [0, 1], 'and': [1], 'eggs': [1, 2]}
notes = ["hello"]
returns {'hello': [0]}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run