17 lines
628 B
Text
17 lines
628 B
Text
DefaultDict[String, Set[String]] index
|
||
|
||
F parse_file(fname, fcontents)
|
||
L(word) fcontents.split(re:‘\W’)
|
||
:index[word.lowercase()].add(fname)
|
||
|
||
L(fname, fcontents) [(‘inv1.txt’, ‘It is what it is.’),
|
||
(‘inv2.txt’, ‘What is it?’),
|
||
(‘inv3.txt’, ‘It is a banana!’)]
|
||
parse_file(fname, fcontents)
|
||
|
||
L(w) [‘cat’, ‘is’, ‘banana’, ‘it’, ‘what’]
|
||
print("\nEnter a word to search for: (q to quit): "w)
|
||
I w C index
|
||
print(‘'#.' found in #..’.format(w, sorted(Array(index[w]))))
|
||
E
|
||
print(‘'#.' not found.’.format(w))
|