From the course: Python: Programming Efficiently

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Challenge: Inverted index

Challenge: Inverted index - Python Tutorial

From the course: Python: Programming Efficiently

Start my 1-month free trial

Challenge: Inverted index

(bright upbeat music) - [Instructor] For your challenge, I'd like you to build an inverted index of the words in Shakespeare's sonnets. Using multi processing pool, to spread the work across multiple process source. This is a toy version of the MapReduce pipelines used by search engines to index the web. The inverted index should look like this. That is, every word across the collection of all sonnets should have its own line, listing all the sonnets they included with the line at which it appears. The sonnets are all included in your exercise files, here's one. To help you out, I'm going to give you a code that makes it partial and sorted index out of one file. Here's what we get for the 15th sonnet. It's okay that the same word appears in multiple lines, you need to reduce those instances into a single line, when you combine the files for multiple sonnets. Another hint, you can use the module glob, to list all the…

Contents