Extra Credit #5

Due: June 5, 2014 at 11:55pm (Note different time)
Points: 30

These two parts have you modify the output to the program “xref2.py” from the last question in the homework. The two parts are independent; you can do neither, either, or both.

  1. (10 points) Take your program “xref2.py” and alter it so that the field width for the words is the length of the longest word in the dictionary. So, for the file “alice.txt”, the first few lines of the output should be:
    
    0              36
    11             13
    1994           14
    20             15
    2008           13
    2011           15
    25             13
    3              36
    A              59
    ADVENTURES     21, 32
    ALICE          21, 32
    ASCII          19
    
    Notice that the numbers are closer to the words than in the homework assignment. As the longest word in that file is “disappointment” (14 letters), the field width for the words is 14, followed by a blank, followed by the list of line numbers.

    Submit. Name your file “xrefx1.py” and submit it to the Extra Credit #5 area for this class on SmartSite.

  2. (20 points) Modify your program in “xref2.py” to eliminate duplicate line numbers in the list of line numbers printed for each word. So, for the file “alice.txt”, the last few lines of the output should be:
    
    words                       101, 170
    world                       68
    worth                       51
    would                       51, 94, 148, 158, 159
    wouldn                      89
    written                     112
    www                         6
    yes                         99
    you                         95, 108, 109, 110, 117, 118, 119, 122, 126, 155, 161, 179, 181, 182
    your                        179
    
    Compare this to the output for the last question in Homework #5; in particular, notice that the line numbers 110 and 179 occur once only.

    Submit. Name your file “xrefx2.py” and submit it to the Extra Credit #5 area for this class on SmartSite.


You can also obtain a PDF version of this. Version of May 30, 2014 at 2:44AM