MC logo
Python Assignment 4
[^] Python Home
[Python Assignment 1] [Python Assignment 2] [Python Assignment 3] [Python Assignment 4] [Python Assignment 5]
[Academy Best Pictures, 1940s] [Academy Best Pictures 2000 Forward]

KWIC! More Python!

Mar 22
Apr 7
70 pts
Update: Corrected the second example output on 3/30.
(If you already had it working to match the old ordering, I'll be happy with that. And it was probably more work.)
A KeWord In Context (KWIC) index is a simple index for a list of lines or titles. This assignment involves creating a KWIC index for an input list of titles. Here's a small example. For the input
The Maltese Falcon
The Big Sleep
your program should produce the output
    3                              The Big Sleep
    1                                  Casablanca
    2                      The Maltese Falcon
    2                              The Maltese Falcon
    3                          The Big Sleep
As you can see, each title is listed for each word (omitting some minor words). The titles are arranged so that the word being indexed is shown in a colum on the page. The line number (starting from 1) is shown on the left.

Your Python solution should follow the following rules:

Here's a longer example. For the input:
It's a Mad, Mad, Mad, Mad World
The Most Amazingly Long Title of Anything You Ever Saw In Your Whole Life
See      Far      Away
Produce the output:
    2                         The Most Amazingly Long Title of Anything You Eve
    2 The Most Amazingly Long Title of Anything You Ever Saw In Your Whole Life
    3                See      Far      Away
    2 ingly Long Title of Anything You Ever Saw In Your Whole Life
    3                         See      Far      Away
    1                                  It's a Mad, Mad, Mad, Mad World
    2 thing You Ever Saw In Your Whole Life
    2               The Most Amazingly Long Title of Anything You Ever Saw In Y
    1            It's a Mad, Mad, Mad, Mad World
    1                           It's a Mad, Mad, Mad, Mad World
    1                      It's a Mad, Mad, Mad, Mad World
    1                 It's a Mad, Mad, Mad, Mad World
    2                              The Most Amazingly Long Title of Anything Yo
    2  Long Title of Anything You Ever Saw In Your Whole Life
    3                                  See      Far      Away
    2          The Most Amazingly Long Title of Anything You Ever Saw In Your W
    2 of Anything You Ever Saw In Your Whole Life
    1        It's a Mad, Mad, Mad, Mad World
    2 Amazingly Long Title of Anything You Ever Saw In Your Whole Life
    2 itle of Anything You Ever Saw In Your Whole Life

Some hints:

When your program works, submit it here.
<<Python Assignment 3 Python Assignment 5>>